PHP Fastest way to get image width and height

Well, i am currently updating my WordPress plugin. I faced a problem in the past to retrieve image width to determine whether a particular image is require to resize. The problem here is that checking a particular image height and width is expensive job. In order to not impact the loading time of the site using my plugin, i forfeited the capability of resizing and resize the image regardless of the size. The plugin works fine since the resizing is doing it on the fly. However, problems arise when a smaller image is being resize and this is not a desirable result. Therefore, i would like to see whether there is a solution exist that can easily solve my problem.

Getting Image size using getImageSize()

Obviously, the task here is talking about PHP, we will look at the getImageSize() functionality exist within the naive php function. I personally was using this on the plugin to determine the size of the image. However, i immediately removed this after i notice the impact this functionality has caused on my site.

The reason? Remote image will need to be downloaded into your server and then it will be read locally by php. The pitfall here is the time used to download remotely to your server. If all your image is in your server and not somewhere else like in a CDN, this might not be a problem.

Better solutions

Well, the better solutions to get image quickly is to create your own script to retrieve the first few bytes of the file since the size of the image is located there. Credit goes to James @ zifiniti.com for the script below,

<?php
   function getimagesize($image_url){
    $handle = fopen ($image_url, "rb");
    $contents = ""; 
    if ($handle) {
    do {
        $count += 1;
        $data = fread($handle, 8192);
        if (strlen($data) == 0) {
            break;
       }   
    $contents .= $data;
    } while(true);
    } else { return false; }
    fclose ($handle);

    $im = ImageCreateFromString($contents);
    if (!$im) { return false; }
    $gis[0] = ImageSX($im);
    $gis[1] = ImageSY($im);
    // array member 3 is used below to keep with current getimagesize standards
    $gis[3] = "width={$gis[0]} height={$gis[1]}";
    ImageDestroy($im);
    return $gis;                                                                                                                                                       
   }   
}
?>

Assuming you have a large image file, this can really come in handle and reduce the time needed to load a site. But, its still slow! xD

Setup WordPress Subversion in Mac

Well, it has been sometimes since i updated this blog actually. In fact, it has been terribly long that i updated some of my plugins (2 years to be exact). I've been busy with setting up Yii framework couponic site and modifying the system as much as possible till i lost track of time. Since i get the time to breath today, i might as well update my plugins. However, i've already forgotten how to do it. Moreover, i am currently using a Macbook air which really gives me zero idea how to connect to my wordpress plugin subversion repository. But i managed to do it anyway and just thought of writing it down a quick tutorial.

For anyone who forgotten how to connect to the repo, here is how you do it. Firstly, you will need a subversion client a.k.a svn client. For windows, you have tortisesvn where you can find the tutorial i wrote two years ago. For Mac, i use versionapps (only 30 days trial :(). Download it and start installing. Once, it is installed, fire up your version apps.  You will be asked for the following few items

The username and password would be your wordpress plugin details. For the location url, just visit your WordPress plugin and click on the tab "Admin". Within there, there is a link call "SVN Repo" as shown below,

You should see the link as shown below,

copy it and pass it into the sub repo and you are done.

Now, just checkout your repo and start doing work! xD

Setup Dell Openmanage on Centos 5.5 with Nagios check_openmanage plugin

Another tutorial that i wish to keep in mind before i need to do research again whenever i setup a new server.Basically for all dell server, you will most likely will like to setup Dell Openmanage software in your Linux server. The reason is pretty simple, Dell openmanage allows you to monitor almost every hardware in your server which can really benefit you a lot whenever some hardware fails.

Anyway, here we go. Firstly, we will need to setup openmanage into my centos 5.5 server. The shortages road to prevent pain is just to key in the following command.

wget -q -O - http://linux.dell.com/repo/hardware/latest/bootstrap.cgi | bash
yum install srvadmin-all -y

P.S: if you see Missing Dependency: perl(LWP::UserAgent) error, please try to go into your /etc/yum.conf to see whether any repo is disabled!

The above command will install dell openmanage for you in centos 5.5. Next you will pretty much need to start dell openmanage service before nagios can do any checking on it. Fire up the following command to start or stop dell openmanage service.

/opt/dell/srvadmin/sbin/srvadmin-services.sh start
/opt/dell/srvadmin/sbin/srvadmin-services.sh stop

There are also other commands such as enable|disable|help|start|stop|restart|status. Once your Dell Openmanage is successfully installed and started. We will have to install one of nagios check_openmanage plugin. Here are the steps to install check_openmanage.

wget "http://folk.uio.no/trondham/software/files/nagios-plugins-check-openmanage-3.7.2-1.el5.x86_64.rpm"
rpm -ivh nagios-plugins-check-openmanage-3.7.2-1.el5.x86_64.rpm

then go to your server nrpe.cfg folder located at /usr/local/nagios/etc/nrpe.cfg and add the command below

command[check_dell_storage]=/usr/lib64/nagios/plugins/check_openmanage --only storage
command[check_dell_fans]=/usr/lib64/nagios/plugins/check_openmanage --only fans
command[check_dell_memory]=/usr/lib64/nagios/plugins/check_openmanage --only memory
command[check_dell_power]=/usr/lib64/nagios/plugins/check_openmanage --only power
command[check_dell_temp]=/usr/lib64/nagios/plugins/check_openmanage --only temp
command[check_dell_cpu]=/usr/lib64/nagios/plugins/check_openmanage --only cpu
command[check_dell_voltage]=/usr/lib64/nagios/plugins/check_openmanage --only voltage
command[check_dell_batteries]=/usr/lib64/nagios/plugins/check_openmanage --only batteries
command[check_dell_amperage]=/usr/lib64/nagios/plugins/check_openmanage --only amperage
command[check_dell_intrusion]=/usr/lib64/nagios/plugins/check_openmanage --only intrusion
command[check_dell_sdcard]=/usr/lib64/nagios/plugins/check_openmanage --only sdcard
command[check_dell_esmhealth]=/usr/lib64/nagios/plugins/check_openmanage --only esmhealth
command[check_dell_esmlog]=/usr/lib64/nagios/plugins/check_openmanage --only esmlog
command[check_dell_alertlog]=/usr/lib64/nagios/plugins/check_openmanage --only alertlog
command[check_dell_critical]=/usr/lib64/nagios/plugins/check_openmanage --only critical
command[check_dell_warning]=/usr/lib64/nagios/plugins/check_openmanage --only warning

Then your monitor server should be able to pick up the instruction and start monitoring your dell hardware 🙂

Pushfix for Malaysia Push Notification fix due to Jailbreak?

Well........ I just bought pushfix after a jailbreak attempt for baseband 6.15.00 with firmware v4.3.3. Everything works well. The only problem i left were the push notification not working. Strictly speaking. The push notification on baseband 6.15.00 does work on my Maxis iphone when it is on 3G. However, it will not work when it is on Wifi. Hence, i decided to try fix it using pushfix 2.0 solution. Without thinking much, i took out my credit card and donated USD6 to pushfix.info. Tried their solutions and it doesn't work 🙁

The reason is pretty simple after the purchase. (dumb me) Our carrier in Malaysia does not required any activation and our push notification does not sent through US server. The solution provided by pushfix.info provide you a unique certification and allow your device to push through US server but this is not require and will not work for us. We will need something else in order for our jailbreak iphone to work on baseband 6.15.00 baseband.

In the case where you wish to purchase the solution provided on pushfix.info. Please do not bother if your device do not require you to communicate with a US server (does not require activation). Peace out ~ [DUMB ME T.T]

September 15 UPDATE******************
Although our push notification does not sent through US server. It seems that it is still necessary to have a unique certificate. In my case, my push notification works but you MUST activate the apps once in order for the push notification to work. If the app is closed, it will still work. However, if you iphone went out of battery or you shut the iphone down, you will need to visit the app again for the push notification to work for that particular app. If you do not have this unique certificate, your push notification is permanently dead unless you don't close your app that is. Good luck!

Websitepanel error codes in WHMCS

As most of you might know that i own a small web hosting film in Malaysia and doing it full time. Currently, i am setting up windows server 2008 with websitepanel. After the setup, i tried to create the products on my whmcs and do a test run. the server response with an error to whmcs but i have no idea what the heck it was. It takes me a long time until i found the following websitepanel error codes which i bet it will be pretty useful for my future reference. So here's the list of websitepanel error codes that appeared on my whmcs apps.

CURRENT_USER_IS_CRM_USER = -2708;
CURRENT_USER_IS_OCS_USER = -2709;
ERROR_ACCOUNT_WIZARD_FTP_ACCOUNT_EXISTS = -1101;
ERROR_ACCOUNT_WIZARD_USER_EXISTS = -1100;
ERROR_ADD_SERVER_APPLICATION_ERROR = -407;
ERROR_ADD_SERVER_BAD_REQUEST = -401;
ERROR_ADD_SERVER_INTERNAL_SERVER_ERROR = -403;
ERROR_ADD_SERVER_NOT_FOUND = -400;
ERROR_ADD_SERVER_SERVICE_UNAVAILABLE = -404;
ERROR_ADD_SERVER_UNAUTHORIZED = -405;
ERROR_ADD_SERVER_URL_UNAVAILABLE = -409;
ERROR_ADD_SERVER_WRONG_LICENSE = -408;
ERROR_ADD_SERVER_WRONG_PASSWORD = -406;
ERROR_BACKUP_DEST_FOLDER_UNAVAILABLE = -2401;
ERROR_BACKUP_SERVER_FOLDER_UNAVAILABLE = -2402;
ERROR_BACKUP_TEMP_FOLDER_UNAVAILABLE = -2400;
ERROR_DNS_PACKAGE_ITEM_NOT_FOUND = -505;
ERROR_DNS_ZONE_EXISTS = -509;
ERROR_DOMAIN_ALREADY_EXISTS = -502;
ERROR_DOMAIN_PACKAGE_ITEM_NOT_FOUND = -504;
ERROR_DOMAIN_POINTS_TO_MAIL_DOMAIN = -507;
ERROR_DOMAIN_POINTS_TO_WEB_SITE = -506;
ERROR_DOMAIN_QUOTA_LIMIT = -500;
ERROR_DOMAIN_STARTS_WWW = -503;
ERROR_DOMAINPOINTERS_QUOTA_LIMIT = -510;
ERROR_EXCHANGE_CONTACTS_QUOTA_LIMIT = -2608;
ERROR_EXCHANGE_DELETE_SOME_PROBLEMS = -2606;
ERROR_EXCHANGE_DLISTS_QUOTA_LIMIT = -2609;
ERROR_EXCHANGE_DOMAINS_QUOTA_LIMIT = -2611;
ERROR_EXCHANGE_EMAIL_EXISTS = -2602;
ERROR_EXCHANGE_MAILBOXES_QUOTA_LIMIT = -2607;
ERROR_EXCHANGE_PFOLDERS_QUOTA_LIMIT = -2610;
ERROR_EXCHANGE_STORAGE_QUOTAS_EXCEED_HOST_VALUES = -2612;
ERROR_FILE_COPY_TO_OWN_SUBFOLDER = -3001;
ERROR_FILE_COPY_TO_SELF = -3000;
ERROR_FILE_CREATE_FILE_WITH_DIR_NAME = -3003;
ERROR_FILE_DEST_FOLDER_NONEXISTENT = -3002;
ERROR_FILE_GENERIC_LOGGED = -3333;
ERROR_FILE_MOVE_PATH_ALREADY_EXISTS = -3004;
ERROR_FP_ACCOUNT_EXISTS = -603;
ERROR_FP_CHANGE_PASSWORD = -604;
ERROR_FTP_PACKAGE_ITEM_EXISTS = -803;
ERROR_FTP_PACKAGE_ITEM_NOT_FOUND = -805;
ERROR_FTP_RESOURCE_QUOTA_LIMIT = -802;
ERROR_FTP_RESOURCE_UNAVAILABLE = -801;
ERROR_FTP_SERVICE_ITEM_EXISTS = -804;
ERROR_FTP_USERNAME_LENGTH = -806;
ERROR_HOSTING_ADDON_USED_IN_PACKAGE = -1502;
ERROR_HOSTING_PLAN_USED_IN_PACKAGE = -1501;
ERROR_INSTANT_ALIAS_IS_NOT_CONFIGURED = -511;
ERROR_INVALID_USER_NAME = -111;
ERROR_IP_USED_BY_PACKAGE_ITEM = -1602;
ERROR_IP_USED_IN_NAME_SERVER = -1601;
ERROR_LICENSE_ALREADY_IN_USE = -2303;
ERROR_LICENSE_LIMITS = -2300;
ERROR_LICENSE_RESELLER_LIMITS = -2304;
ERROR_MAIL_ACCOUNTS_PACKAGE_ITEM_EXISTS = -703;
ERROR_MAIL_ACCOUNTS_PACKAGE_ITEM_NOT_FOUND = -714;
ERROR_MAIL_ACCOUNTS_RESOURCE_QUOTA_LIMIT = -702;
ERROR_MAIL_ACCOUNTS_SERVICE_ITEM_EXISTS = -704;
ERROR_MAIL_DOMAIN_EXISTS = -700;
ERROR_MAIL_DOMAIN_IS_NOT_EMPTY = -720;
ERROR_MAIL_DOMAIN_PACKAGE_ITEM_NOT_FOUND = -718;
ERROR_MAIL_DOMAIN_SERVICE_ITEM_NOT_FOUND = -719;
ERROR_MAIL_FORWARDINGS_PACKAGE_ITEM_EXISTS = -706;
ERROR_MAIL_FORWARDINGS_PACKAGE_ITEM_NOT_FOUND = -715;
ERROR_MAIL_FORWARDINGS_RESOURCE_QUOTA_LIMIT = -705;
ERROR_MAIL_FORWARDINGS_SERVICE_ITEM_EXISTS = -707;
ERROR_MAIL_GROUPS_PACKAGE_ITEM_EXISTS = -709;
ERROR_MAIL_GROUPS_PACKAGE_ITEM_NOT_FOUND = -716;
ERROR_MAIL_GROUPS_RECIPIENTS_LIMIT = -721;
ERROR_MAIL_GROUPS_RESOURCE_QUOTA_LIMIT = -708;
ERROR_MAIL_GROUPS_SERVICE_ITEM_EXISTS = -710;
ERROR_MAIL_LICENSE_DOMAIN_QUOTA = -723;
ERROR_MAIL_LICENSE_USERS_QUOTA = -724;
ERROR_MAIL_LISTS_PACKAGE_ITEM_EXISTS = -712;
ERROR_MAIL_LISTS_PACKAGE_ITEM_NOT_FOUND = -717;
ERROR_MAIL_LISTS_RECIPIENTS_LIMIT = -722;
ERROR_MAIL_LISTS_RESOURCE_QUOTA_LIMIT = -711;
ERROR_MAIL_LISTS_SERVICE_ITEM_EXISTS = -713;
ERROR_MAIL_RESOURCE_UNAVAILABLE = -701;
ERROR_MSSQL_DATABASES_PACKAGE_ITEM_EXISTS = -903;
ERROR_MSSQL_DATABASES_PACKAGE_ITEM_NOT_FOUND = -908;
ERROR_MSSQL_DATABASES_RESOURCE_QUOTA_LIMIT = -902;
ERROR_MSSQL_DATABASES_SERVICE_ITEM_EXISTS = -904;
ERROR_MSSQL_RESOURCE_UNAVAILABLE = -901;
ERROR_MSSQL_USERS_PACKAGE_ITEM_EXISTS = -906;
ERROR_MSSQL_USERS_PACKAGE_ITEM_NOT_FOUND = -909;
ERROR_MSSQL_USERS_RESOURCE_QUOTA_LIMIT = -905;
ERROR_MSSQL_USERS_SERVICE_ITEM_EXISTS = -907;
ERROR_MYSQL_DATABASES_PACKAGE_ITEM_EXISTS = -1003;
ERROR_MYSQL_DATABASES_PACKAGE_ITEM_NOT_FOUND = -1008;
ERROR_MYSQL_DATABASES_RESOURCE_QUOTA_LIMIT = -1002;
ERROR_MYSQL_DATABASES_SERVICE_ITEM_EXISTS = -1004;
ERROR_MYSQL_INVALID_DATABASE_NAME = -1011;
ERROR_MYSQL_INVALID_USER_NAME = -1010;
ERROR_MYSQL_RESOURCE_UNAVAILABLE = -1001;
ERROR_MYSQL_USERS_PACKAGE_ITEM_EXISTS = -1006;
ERROR_MYSQL_USERS_PACKAGE_ITEM_NOT_FOUND = -1009;
ERROR_MYSQL_USERS_RESOURCE_QUOTA_LIMIT = -1005;
ERROR_MYSQL_USERS_SERVICE_ITEM_EXISTS = -1007;
ERROR_NOT_ENTERPRISE_SERVER_LICENSE = -2301;
ERROR_NOT_SERVER_LICENSE = -2302;
ERROR_ORG_EMAIL_EXISTS = -2702;
ERROR_ORG_ID_EXISTS = -2701;
ERROR_ORGANIZATION_DELETE_SOME_PROBLEMS = -2706;
ERROR_ORGANIZATION_DOMAIN_IS_IN_USE = -2705;
ERROR_ORGANIZATION_TEMP_DOMAIN_IS_NOT_SPECIFIED = -2704;
ERROR_ORGS_RESOURCE_QUOTA_LIMIT = -2703;
ERROR_OS_DSN_PACKAGE_ITEM_EXISTS = -2103;
ERROR_OS_DSN_PACKAGE_ITEM_NOT_FOUND = -2105;
ERROR_OS_DSN_RESOURCE_QUOTA_LIMIT = -2102;
ERROR_OS_DSN_SERVICE_ITEM_EXISTS = -2104;
ERROR_OS_RESOURCE_UNAVAILABLE = -2101;
ERROR_OS_SCHEDULED_TASK_QUOTA_LIMIT = -2200;
ERROR_PACKAGE_CANCELLED = -304;
ERROR_PACKAGE_HAS_PACKAGES = -301;
ERROR_PACKAGE_NEW = -302;
ERROR_PACKAGE_NOT_FOUND = -300;
ERROR_PACKAGE_QUOTA_EXCEED = -305;
ERROR_PACKAGE_SUSPENDED = -303;
ERROR_RESTORE_BACKUP_SOURCE_NOT_FOUND = -2503;
ERROR_RESTORE_BACKUP_SOURCE_UNAVAILABLE = -2502;
ERROR_RESTORE_INVALID_BACKUP_SET = -2501;
ERROR_RESTRICTED_DOMAIN = -501;
ERROR_SERVER_CONTAINS_PACKAGES = -1702;
ERROR_SERVER_CONTAINS_SERVICES = -1701;
ERROR_SERVER_USED_IN_HOSTING_PLANS = -1703;
ERROR_SERVICE_CONTAINS_SERVICE_ITEMS = -1801;
ERROR_SERVICE_USED_IN_VIRTUAL_SERVER = -1802;
ERROR_SETTINGS_ACCOUNT_LETTER_EMPTY_BODY = -200;
ERROR_SETTINGS_PACKAGE_LETTER_EMPTY_BODY = -201;
ERROR_SETTINGS_PASSWORD_LETTER_EMPTY_BODY = -202;
ERROR_SHAREPOINT_GROUPS_PACKAGE_ITEM_EXISTS = -1406;
ERROR_SHAREPOINT_GROUPS_PACKAGE_ITEM_NOT_FOUND = -1409;
ERROR_SHAREPOINT_GROUPS_RESOURCE_QUOTA_LIMIT = -1405;
ERROR_SHAREPOINT_GROUPS_SERVICE_ITEM_EXISTS = -1407;
ERROR_SHAREPOINT_PACKAGE_ITEM_EXISTS = -2003;
ERROR_SHAREPOINT_PACKAGE_ITEM_NOT_FOUND = -2004;
ERROR_SHAREPOINT_RESOURCE_QUOTA_LIMIT = -1410;
ERROR_SHAREPOINT_RESOURCE_UNAVAILABLE = -2001;
ERROR_SHAREPOINT_USERS_PACKAGE_ITEM_EXISTS = -1403;
ERROR_SHAREPOINT_USERS_PACKAGE_ITEM_NOT_FOUND = -1408;
ERROR_SHAREPOINT_USERS_RESOURCE_QUOTA_LIMIT = -1402;
ERROR_SHAREPOINT_USERS_SERVICE_ITEM_EXISTS = -1404;
ERROR_STATS_PACKAGE_ITEM_EXISTS = -1303;
ERROR_STATS_PACKAGE_ITEM_NOT_FOUND = -1305;
ERROR_STATS_RESOURCE_QUOTA_LIMIT = -1302;
ERROR_STATS_RESOURCE_UNAVAILABLE = -1301;
ERROR_STATS_SERVICE_ITEM_EXISTS = -1304;
ERROR_SUBDOMAIN_QUOTA_LIMIT = -508;
ERROR_USER_ACCOUNT_CANCELLED = -105;
ERROR_USER_ACCOUNT_DEMO = -106;
ERROR_USER_ACCOUNT_PENDING = -103;
ERROR_USER_ACCOUNT_SHOULD_BE_ADMINISTRATOR = -107;
ERROR_USER_ACCOUNT_SHOULD_BE_RESELLER = -108;
ERROR_USER_ACCOUNT_SUSPENDED = -104;
ERROR_USER_ALREADY_EXISTS = -100;
ERROR_USER_HAS_USERS = -102;
ERROR_USER_NOT_FOUND = -101;
ERROR_USER_SERVER_WRONG_AD_SETTINGS = -402;
ERROR_USER_WRONG_PASSWORD = -110;
ERROR_USER_WRONG_USERNAME = -109;
ERROR_USERS_RESOURCE_QUOTA_LIMIT = -2707;
ERROR_VDIR_ALREADY_EXISTS = -605;
ERROR_WEB_INSTALLER_CANT_CONNECT_DATABASE = -1202;
ERROR_WEB_INSTALLER_TARGET_DATABASE_UNSUITABLE = -1204;
ERROR_WEB_INSTALLER_TARGET_WEBSITE_UNSUITABLE = -1203;
ERROR_WEB_INSTALLER_WEBSITE_NOT_EXISTS = -1201;
ERROR_WEB_SHARED_SSL_QUOTA_LIMIT = -609;
ERROR_WEB_SITE_ALREADY_EXISTS = -601;
ERROR_WEB_SITE_IP_ADDRESS_NOT_SPECIFIED = -607;
ERROR_WEB_SITE_PACKAGE_ITEM_NOT_FOUND = -606;
ERROR_WEB_SITE_SERVICE_UNAVAILABLE = -602;
ERROR_WEB_SITE_SHARED_IP_ADDRESS_NOT_SPECIFIED = -608;
ERROR_WEB_SITES_QUOTA_LIMIT = -600;
FAILED_EXECUTE_SERVICE_OPERATION = -999;
SMTP_BAD_COMMAND_SEQUENCE = -1901;
SMTP_CANNOT_VERIFY_USER_WILL_ATTEMPT_DELIVERY = -1902;
SMTP_CLIENT_NOT_PERMITTED = -1903;
SMTP_COMMAND_NOT_IMPLEMENTED = -1904;
SMTP_COMMAND_PARAMETER_NOT_IMPLEMENTED = -1905;
SMTP_COMMAND_UNRECOGNIZED = -1906;
SMTP_EXCEEDED_STORAGE_ALLOCATION = -1907;
SMTP_GENERAL_FAILURE = -1908;
SMTP_INSUFFICIENT_STORAGE = -1909;
SMTP_LOCAL_ERROR_IN_PROCESSING = -1910;
SMTP_MAILBOX_BUSY = -1911;
SMTP_MAILBOX_NAME_NOTALLOWED = -1912;
SMTP_MAILBOX_UNAVAILABLE = -1913;
SMTP_MUST_ISSUE_START_TLS_FIRST = -1914;
SMTP_SERVICE_CLOSING_TRANSMISSION_CHANNEL = -1915;
SMTP_SERVICE_NOT_AVAILABLE = -1916;
SMTP_SYNTAX_ERROR = -1917;
SMTP_TRANSACTION_FAILED = -1918;
SMTP_UNKNOWN_ERROR = -1921;
SMTP_USER_NOT_LOCAL_TRY_ALTERNATE_PATH = -1919;
SMTP_USER_NOT_LOCAL_WILL_FORWARD = -1920;

If anyone of you need web hosting in Malaysia, contact me and i shall provide you with a special discount and help you as much as possible. Hope the article helps 🙂