Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Alex Zorin:
Shimming PHP for Fun and Profit
Nov 28, 2016 @ 15:45:48

On his site recently Alex Zorin posted an article about shimming PHP for fun and profit making use of the runkit functionality to override some of the basic PHP handling.

I had spent a short amount of time profiling the application some months ago. By all indications, the framework upon which the site was built was doing something really stupid.

[...] For somebody who is comfortable finding and fixing hotspots like this, it sounds like a dream come true. Not so. A quick grep through the code indicated that that particular hotspot existed in at least a dozen different points in the code base. As my role in this scenario was an ops. engineer, touching the client’s codebase was a no-no.

He first looked into something he could add at the Zend Engine level itself but then veered more towards custom functionality that overrides some base64 handling in the language. There were some difficulties following this path so he shifted to another tactic - using runkit. He implemented this "monkey patching" solution using the runkit handling and integrated it into his client's installation reducing the load time by about 10 seconds on the largest, slowest request he could find. He also includes a link to the code if you're interested in seeing how he accomplished this optimization.

tagged: shim runkit language optimize base64 extension

Link: https://id-rsa.pub/post/shimming-php-for-fun-and-profit/

Davey Shafik:
PHP 7 ext/mysql Shim
Dec 07, 2015 @ 17:10:24

With the release of PHP 7 comes a major shift in how your programs may interact with databases - the removal of the mysql extension (in favor of mysqli or PDO). Depending on how your application is written, this can cause all sorts of headaches. Davey Shafik has offered a temporary solution in a post to his site today, a mysql shim library that can be used to mimic the older mysql functions until you can upgrade your application.

To help ease the transition from 5.6 to 7.0 I have created a simple package that acts as a shim between the newly removed ext/mysql and ext/mysqli. I was a little hesitant to even publish this as I don’t want to encourage the continued use of potentially insecure code, however, I want people to upgrade to 7.0 and don’t want this to be the blocker.

It does require 5.6 (though it would be possible to lower that) — however I suspect that most people who are upgrading to 7.0 are either coming from 5.6 or have the native ext/mysql. The primary reason for support 5.6 is to be able to compare the test suite results against native ext/mysql.

The library can be easily installed via Composer and, while useful in its current form, still has some work yet to be done on it to bring it up to fully compatible. If you'd like to help on the effort and make life a little easier for those upgrading to PHP 7 on older code, head over to the repository and think about contributing.

tagged: mysql extension php7 shim library backport upgrade

Link: https://daveyshafik.com/archives/69726-php-7-extmysql-shim.html


Trending Topics: