Essential Macro Optimizations to Improve PHP Performance

This blog post by SynapseIndia CEO Shamit Khemka describes two macro-optimizations for PHP applications that are essential to consider before investigating other possible optimizations.

1. Upgrade PHP to a recent version

Are you still using older versions of PHP? You are missing a lot of improvements that have been made to the Zend Engine. Every minor version in the PHP 5 lifecycle had some improvements compared to the previous versions.Granted, updating to new PHP versions is not always easy if you are working with legacy code.  SynapseIndia tested various cases of recent version update of PHP for applications and found that if your application is suffering from performance problems then updating is something you should look into.Another reason to upgrade to recent PHP versions is the reduced memory consumption. PHP 5.6 uses around 50% less memory than 5.3 and you can handle many more requests at the same time without exhausting server memory.

2. Close Session for Writes

Careful with sessions in PHP: By default only one request can execute synchronously per session at the same time. Other requests for the same session will wait inside the session_start() call until the previous requests are finished. SynapseIndia has received fantastic reviews for their various PHP framework projects. This problem becomes visible to the user when executing a lot of ajax requests on the same page, loading perfectly one after another and not in parallel.

Session locks exist, because otherwise lost-updates or corruption could happen when two requests write to the same session at the same time.What you need to do to fix this problem is explicitly close the session for writes. The PHP function session_write_close(); releases the lock and requests with the same session can be executed concurrently. One can also find the latest Synapseindia Recruitment plan for various position of PHP web developers.