Category Archives: PHP

Fix: XAAMP Apache can not start in XP

One day after rebooting my Windows XP my XAAMP Apache 2.0 was unable to start. Here is what the error log showed”

[Sun Sep 20 15:01:00 2009] [crit] (OS 2)The system cannot find the file specified.  : Parent: Unable to connect child stdout to NUL.
[Sun Sep 20 15:01:00 2009] [crit] (OS 2)The system cannot find the file specified.  : master_main: create child process failed. Exiting.
[Sun Sep 20 15:01:00 2009] [error] (OS 6)The handle is invalid.  : Parent: SetEvent for child process 0 failed

So while trying to find a solution for this problem, which in the beginning looked like a Apache related problem (I tried reinstalling XAAMP several times in different directories etc…) I found out that it actually was a Windows XP problem.  Somehow the NULL driver on my PC has stopped working.  So how to fix this problem:

  1. Open the Device Manager (right click My Computer -> Properties -> Hardware)
  2. From the View menu select Show Hidden Devices
  3. From the Non-Plug and Play Drivers group find the Null driver right click it and Uninstall it
  4. Restart your PC and start Apache from the XAAMP control center

I hope this helps!

PHP Listing pages optimization

Recently I was asked to develop a website that had a product page listing of over over 20.000 products. The SELECT query to get the products was optimized as much as it could be. But it was not enough! Due to the high volume of traffic this product listings have the server was always with load over 2 (Cent OS using top). I was forced to use a simple optimization that in the end came out to be quite effective.

To get the product listing there were 2 queries. If we simplify them they would look something like this:

SELECT COUNT(*) FROM products WHERE .....

SELECT something FROM products WHERE ..... LIMIT start, offset;

So even though the COUNT(*) in MySQL goes pretty fast it uses a lot of memory. This COUNT(*) was needed to find out how many products were there and display the number of pages.


So instead of having this 1,2,3,4… page numeration I got it down to prev/next


Here comes the trick. The first 1,2,3,4… navigation requires 2 SQL queries to be done. The second one requires ONLY ONE.

The trick is to select one more result than you are actually showing. Let’s say that you want to display 20 results per page, you select 21. If the 21st record exists than you have a “next page” if it doesn’t you don’t.

What about the “previous page” link?

The LIMIT start, offset in the SQL query will tell you if you have a “previous page” if this number is different from 0 (start !=0) or to be more specific

if(($start - $records_per_page) <= 0)

you have a previous page.

This technique is useful for high volume traffic sites where every hardware resource matters. It can not be applied on all listings due to design/functionality issues, but in some cases it could be a life saver.

Getting NuSOAP to work in PHP5

After a night of angry typing and googling to find a solution why my scripts that worked on PHP 4.2 and used NuSOAP now show the following error on PHP 5:

Fatal error: Cannot redeclare class soapclient in D:\www\nusoap.php on line 7240

The thing is that PHP5 has its own built in class soapclient and this is where the error comes from.

The solution to get NuSOAP working on PHP5 is quite simple. Open the nusoap.php file and replace soapclient with mysoapclient or whatever you think of. Use a mass find/replace if supported by your editor.