Archive for the ‘PHP’ category

Installing apache, fastcgi & php-fpm on dragonflybsd

November 18th, 2011

We’re cur­rently in the pro­cess of tran­si­tio­ning our web ser­vers from NetBSD to Dra­gon­flyBSD; along with that, we’re also swit­ching our PHP plat­form to php-fpm. There are a few les­sons we lear­ned in the process.

First: At least on Dra­gon­flyBSD 2.10, apache2 does not at all per­form well as apache-mpm-worker. Swit­ching to apache-mpm-prefork chan­ged our CPU load from 98% of apa­che to about 3 – 5% of apache.

Also, php-fpm was deli­ve­r­ing too high a rate of 500 errors; this was not accep­ta­ble to our cust­o­mers. Inves­ti­ga­ti­ons into that lead me to the blog arti­cle at http://​alexca​bal​.com/​i​n​s​t​a​l​l​i​n​g​-​a​p​a​c​h​e​-​m​o​d​_​f​a​s​t​c​g​i​-​p​h​p​-​f​p​m​-​o​n​-​u​b​u​n​t​u​-​s​e​r​v​e​r​-​m​a​v​e​r​i​c​k​/​#​c​o​m​m​e​nts, which then sent me link-chasing to – ulti­mately – http://​arti​cle​.gmane​.org/​g​m​a​n​e​.​c​o​m​p​.​w​e​b​.​f​a​s​t​c​g​i​.​d​e​v​e​l​/​2​514. This means we now have a set of local patches to our pkgsrc tree that incor­po­rate the patch from this pos­ting. At first sight, this seems to have impro­ved the situation.

The library now is able to …

March 29th, 2011

I’m cur­rently wri­t­ing a library of PHP stuff for our inter­nal use. I’ve been able to make it do a few fun tricks.

To express a query with a sub­query, I can now do this:
$sube = new Expression('subtable');
$sube->setResultField('id');
$sube->beginGroup('and');
$sube->addTerm('field1','=',$valueA);
$sube->addTerm('field2','< =','expr:now()');
$sube->endGroup;
$e = new Expression('table');
$e->addTerm('field2','not in',$sube);

$XQDB->getObjects($e);

I like that!

Requiring code in PHP

August 12th, 2010

While wri­t­ing the code to handle a small form in PHP, I just rea­li­zed that I have a very bad habit — and many just do the same.

When I write a new file, I place all the includes at the very top, before anything else hap­pens. But in my cur­rent script, there are many code paths that do not require the major part of all those inclu­des. Only in one spe­ci­fic instance do we require the bulk of the code. Pre­viously, any invo­ca­tion of that script would have got­ten all the code drag­ged in. Now, I’ve moved the include to just where I need the code (basi­cally, going into a spe­ci­fic case of a lar­ger switch state­ment … And the load on the web ser­ver has just been redu­ced, wit­hout any change to the functionality.

So why do we all put the inclu­des on top?