Make Better Things

I like to make better things.

installing zend debugger on xampp and setting it up with zend studio

If you have XAMPP installed, the Zend Optimizer will be installed by default, and this causes the standard installation of Zend Debugger to fail. Follow the steps below for success.

1) Make sure you have a running installation of XAMPP. Installing XAMPP is not part of this article. You can test your installation by entering http://localhost/xampp/ in a browser.

2) Enter http://localhost/xampp/phpinfo.php in the address bar of your browser. Note the information about Zend Extension Manager and Zend Optimizer. By the end of this article, Zend Debugger will be added.

3) Download the latest .zip file for cygwin_nt-i386 from and unpack into xamppphpzendDebuggerlibDebugger. Caution: In a standard XAMPP installation, the instructions in the README.txt file in this download will cause Apache not to start. See the following steps instead.

4) Rename the the subdirectories from “4_3_x_comp” etc. to “php-4.3.x” etc. see image.


Rename directories

5) Copy the file dummy.php in the download to your Apache htdocs directory, for example xampphtdocsdummy.php. This what all the instructions and help files say, but I forgot it on one installation and didn’t notice any problems. It can’t hurt to do it though.

6) Search the PHPInfo that you ran in step 2 for the value “Loaded Configuration File”. Open this php.ini file in a text editor. You might want to save a copy of it before editing it.

7) If you have XAMPP you will find some lines in php.ini that look like this:

zend_extension_ts = “G:xamppphpzendOptimizerlibZendExtensionManager.dll”
zend_extension_manager.optimizer_ts = “G:xamppphpzendOptimizerlibOptimizer”
zend_optimizer.enable_loader = 0

;zend_optimizer.license_path =
; Local Variables:
; tab-width: 4
; End:

8 ) If you see the lines in step 7 and follow the instructions from README.txt in the download in step 3, you will be adding a second zend_extension_ts line. This will cause Apache not to start. Instead, add the following lines:
zend_extension_manager.debug_server_ts = “xamppphpzendDebuggerlibDebugger”
zend_debugger.allow_hosts =
zend_debugger.expose_remotely = allowed_hosts

9) Restart XAMPP, for example by calling xamppxampp_restart.exe. Reload PHPInfo; now it should look like this new image. Note the new information about Zend Debugger.

zend debugger

zend debugger

Face Detection in PHP using Open CV

In this article, i will explain how possible this task can be achieved with simplicity with OpenCV and PHP Facedetect extension. Both are free to download and opensource.


To auto detect faces in a photo and draw pink box around the faces with a php script running a linux centos server. Please note that face detection and face recognition are two different things. To recognize a face you have to first detect a face and then do the required processing.


- Linux server running Centos with SSH access

- PHP/Apache

- GD Library

- OpenCV [Download]

- PHP Facedetect extension [Download]

PHP facedetect extension is very simple. All you have to do is call a function face_detect(p) and it will give all the x,y coordinates in a photo where we draw a square. face_count() will output how many total faces in the given photo. For documentation see here


We install opencv and then we compile the php facedetect extension with php.

How to Install OpenCV

If you are running centos then one single line will install opencv.

  yum install opencv

OpenCV may also need the following depencies to work properly and you will need to install them as well.

 yum install ibpng libpng-dev zlib libjpeg libjpeg-dev libtiff libjasper swig python pkgconfig gtk gtk-dev

For more installation instructions on linux see here

The opencv will be installed in/usr/local/share/opencv and all the important facedetection training files known as “haar training” can be found in haarcascades folder in xml format (like haarcascade_frontalface_alt.xml)

How to test run OpenCV

Inorder to test run opencv you have to compile the samples folder. Go to /usr/local/share/opencv/samples/c/

Run this command to compile to binary.


If you find large number of errors and variables not declared like shown below..

  Package opencv was not found in the pkg-config search path.
    Perhaps you should add the directory containing `opencv.pc’
    to the PKG_CONFIG_PATH environment variable
    No package ‘opencv’ found


  export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

and then it will compile.

To test run the opencv run the following command in the c folder for a test.jpg photo.

  ./facedetect –cascade=”../haarcascades/haarcascade_frontalface_alt.xml” test.jpg

Since your server does not have Xwindow installed, you probably do not see the output just the processing time.

If you see error “error while loading shared libraries: cannot open shared object file: No such file or directory” then see this solution

Install PHP Facedetect Extension

Installing the PHP facedetect extension is very easy. Just download the package and compile it for PHP.

  wget [download_file_path]
  tar zxf facedetect-1.0.0


  phpize && configure && make && make install

If you see phpize command not found error, install php developer libraries

  yum install php-devel
  yum install php5-devel


open php.ini and make sure you add this line.

Thats it! all the installation part is over!

Writing a PHP Script

Before you start writing php script make sure you copy all xml files in /usr/local/share/opencv/haarcascades folder to the web folder.

and this simple two lines to from php to call the function

//face_count() outputs total faces detected
// face_detect() outputs assoc array of x,y,width,height of each face recognized

$total= face_count('test.jpg','haarcascade_frontalface_alt.xml');
$coord= face_detect('test.jpg','haarcascade_frontalface_alt.xml');

Make sure the path of xml files are correct else you would see a blank face or bool(false) output. Once you get this co-ordinates all we have to do is use php gd library to draw square around the face with the above coordinates.

This script will do that and you have call the script with photo file like this http://domain/face.php?file=test.jpg and the test.jpg file should be in the same folder

//face.php -> detects faces and draws a pink square on faces

function LoadJpeg($imgname)
 $im = @imagecreatefromjpeg($imgname); /* Attempt to open */
 if (!$im) { /* See if it failed */
 $im  = imagecreate(150, 30); /* Create a blank image */
 $bgc = imagecolorallocate($im, 255, 255, 255);
 $tc  = imagecolorallocate($im, 0, 0, 0);
 imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
 /* Output an errmsg */
 imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
 return $im;

$total= face_count($_GET['file'],'haarcascade_frontalface_alt.xml');
$ord= face_detect($_GET['file'],'haarcascade_frontalface_alt.xml');

$im = LoadJpeg($_GET['file']);
$pink = imagecolorallocate($im, 255, 105, 180);

if(count($ord) > 0) {

foreach ($ord as $arr) {
imagerectangle($im,$arr['x'] ,$arr['y'] , $arr['x']+$arr['w'],
$arr['y']+$arr['h'], $pink);

header('Content-Type: image/jpeg');

Just remember haarcascade_frontalface_alt.xml are haar training files used for face detection. You can play around with other training files like to detect various body parts, not just faces.


Conclusion and the Results

(standard test image used for image processing)

Face Detection with PHP

Face Detection with PHP

I have given multiple frontal detection photos to the script and the script performed well, despite few false face detections.

I should say i am pretty surprised the way the multiple faces are detected and the results are good with haarcascade_frontalface_alt.xml as training file . To get more accurate results, you need to do haar training to xml files to produce more accurate results.

Other Useful Links

Facedetection with pure PHP without OpenCV [visit site]

Facedetection with javascript [visit site]

OpenCV Face Detection Page [visit site]