Tuesday, 3 November 2015

MapGuide tidbits: Improving bundled PHP performance

NOTE: This tip only applies to PHP that is bundled with MapGuide Open Source 2.6 and newer.

MapGuide Open Source 2.6 and newer bundles the 5.5.x series of PHP, which includes a new opcode caching feature. Opcode caching can reduce execution times by upwards of 50% (as is the case with our mapguide-rest functional test suite which usually took around 6 minutes to run, but now runs in just over 3 minutes with opcode caching enabled)

In the interest of playing it safe, we didn't activate this feature in the default php.ini that's bundled with MapGuide. So if you want to activate this feature, you'll have to edit php.ini and add the following lines:

;Enable the opcode caching extensions
zend_extension=php_opcache.dll
;On Linux, the path should be
;zend_extension=/usr/local/mapguideopensource-x.y.z/webserverextensions/php/lib/php/extensions/no-debug-zts-20121212/opcache.so

;Some default opcode caching options. Adjust as necessary
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1

Save the file (and restart the web server to re-jig PHP if required) and enjoy your faster PHP scripts!

UPDATE (18 Nov): Upon further testing, I've been finding that PHP opcache is horribly unstable on Windows (see this and this). So enable this feature at your own peril!

3 comments:

Unknown said...

How about AIMS users? Do they have the same capability to improve their PHP performance?
For example, I am using AIMS 2014, and it's bundled with PHP 5.3.8. Is there anyway I can have this improvement too? Thank you :)

Jackie Ng said...

You'll have to use a third-party opcode cache extension like APC:

http://pecl.php.net/package/APC

Unknown said...

Hi Jackie,

Thank you for your reply. I found following sites introduce me where to download, and enable APC extension.

https://docs.moodle.org/22/en/Installing_APC_in_Windows
http://dev.freshsite.pl/php-accelerators/apc.html.
http://pecl.php.net/package/APC/3.1.13/windows

However, my PHP version is 5.3.8-Win64, and the compiler is MSVC10(Visual C++ 2010). Thread Safety is enabled, and the system is Windows Server 2008 R2. The server API is CGI/FastCGI.

I am not sure which version should I download.

Since when I enabled 5.3 Thread Safe (TS) x86/APC 3.1.14 beta for PHP 5.3 (Win7/2008)/nts version, I couldn't check my phpinfo().

I added code under php.ini after extension=php_gd2.dll as following:
extension=php_apc.dll

It showed me an IIS erro page.

HTTP Error 500.0 - Internal Server Error
C:\Program Files\Autodesk\Autodesk Infrastructure Web Server Extension 2014\Php\php-cgi.exe - The FastCGI process exited unexpectedly

Module FastCgiModule
Notification ExecuteRequestHandler
Handler PHP via FastCGI
Error Code 0x000000ff
Requested URL http://localhost:80/MapServer2014/0xlwuwzm.php
Physical Path C:\Program Files\Autodesk\Autodesk Infrastructure Web Server Extension 2014\www\0xlwuwzm.php
Logon Method Anonymous
Logon User Anonymous

Most likely causes:
IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.


Thanks,
Reno