Archive for the ‘PHP’ Category

PHP Performance Tip

Saturday, June 4th, 2011

To improve the performance of your PHP application, you should work with object properties directly, rather than writing naive settings and getters. If you need getter/setters, you can use the __get and __set magic methods.

I have performed a quick test with the following script (base code is from google performance tips) to show the performance savings.

php -d implicit_flush=off -r ‘class dog { public $name = “”;} $rover = new dog(); for ($x=0; $x<10; $x++) { $t = microtime(true); for ($i=0; $i<1000000; $i++) { $rover->name = “rover”; $n = $rover->name;} echo microtime(true) – $t;echo “\n”;}’
0.27138209342957
0.27215003967285
0.27119302749634
0.27127695083618
0.27089595794678
0.27323412895203
0.27595901489258
0.27139592170715
0.27534413337708
0.27470207214355

php -d implicit_flush=off -r ‘class dog {public $name = “”;public function setName($name) {$this->name = $name; }public function getName() {return $this->name; } }$rover = new dog();for ($x=0; $x<10; $x++) { $t = microtime(true);for ($i=0; $i<1000000; $i++) { $rover->setName(“rover”);$n = $rover->getName();}echo microtime(true) – $t;echo “\n”;}’
0.88418102264404
0.90805292129517
0.88095903396606
0.9102931022644
0.88606786727905
0.91241002082825
0.88503313064575
0.90973210334778
0.87963604927063
0.91335105895996

php -d implicit_flush=off -r ‘class dog {public $name = “”;public function __set($key, $value) {$this->$key = $value;}public function __get($key) {return $this->$key;}}$rover = new dog(); for ($x=0; $x<10; $x++) { $t = microtime(true); for ($i=0; $i<1000000; $i++) { $rover->name = “rover”; $n = $rover->name;} echo microtime(true) – $t;echo “\n”;}’
0.27974605560303
0.28078198432922
0.27995705604553
0.280522108078
0.27998900413513
0.28067207336426
0.27970504760742
0.28028988838196
0.27951693534851
0.28037190437317

Installing PHP extensions on Mac OS X under xampp

Monday, May 31st, 2010

The other day I installed xampp on a mac os x running snow leopard but I was having an issue installing any extra extensions like xdebug and apc. I found out it was because it was compiling the extensions in 64bit but xampp is compiled in 32bit and I did the following to fix the issue:

  1. Download and extract the source
  2. Run phpize
  3. Adding the following parameters to configure:
    ./configure MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS="-arch i386 -g -Os -pipe -no-cpp-precomp" CCFLAGS="-arch i386 -g -Os -pipe" CXXFLAGS="-arch i386 -g -Os -pipe" LDFLAGS="-arch i386 -bind_at_load"
  4. make (and make install if required)
  5. done :)

If that doesnt work, try adding:

--with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1

to the configure command.

I hope that will help some people out there, because it was driving me insane!

I got reddited

Monday, May 31st, 2010

Last week my post got posted on reddit and was on the homepage for over 24 hours which I as totally not expecting and the end results was my blog being down for a large amount of time over those couple of days. I had to set my DNS records to 127.0.0.1 as all I had at the time to fix the issue was my phone and since I receive free hosting from my old company (WebClick – http://www.webclick.com.au) the last thing I wanted to do was crash their servers.

I have now installed wp-supercache so hopefully if it every happens again, my blog will handle it 10x better.

OpenCart Secured Issue

Monday, March 29th, 2010

I have been meaning to post this early but there is a problem now with the secure patch for OpenCart that means my release no longer works. As of 1.4.1, the developer made a change to how all the links are made, well rather than running the links through a function which can re-write the URL (which my patch added a random token too). The change he made was to make every URL static therefore I am no longer able to add the token to every URL automatically, but to add the token manually to every link which I am deciding against doing from a pure maintenance level (and a nightmare to upgrade).

The only reason why I could see the developer to make this change is to kill the development of my patch. I now have a few options and would love to hear any feedback on which path to take.

1. Revert back to 1.4.0 and no longer do anymore upgrades.
2. Delete the project so it no longer exists.
3. For someone else to takeover who has the time to do any maintenance required (which I don’t have).

Personally I think the developer of OpenCart has lost the plot and I believe people should look at other options that have a more dynamic development process, and a team who knows what they are doing.

Update: I have since deleted the repo’s on GitHub as the code no longer works and I am unable to fix all the security issues.

OpenCart Secured Upgraded to 1.4.1

Tuesday, March 9th, 2010

Quick blog post, just letting everyone know I have update OpenCart Secured to version 1.4.1. If you notice any problems please let me know.

You can grab it here: http://github.com/bmaynard/OpenCart-Secured

Update: I have now upgraded the repository to 1.4.2

Update 2: I have now upgraded the repository to 1.4.4