|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-02-26 22:29 UTC] nigel at green-bean dot com
Summary: Running a PHP script which calls exec() from withing Apache runs terribly slow or times out. Running same from the command prompt returns in seconds. Details: I (and other NT users) have run into performance issues running PHP 4.1.1 with the NETPBM distribution. When running thumbnailing operations via. webpages, the performance (throughtput) of the system is dismal. Running the same PHP script manually from the command shell completes operations in under a second which usually timeout when executed from a webpage. A full "ready to run" repro of this problem is available via. a small ZIP file at http://www.green-bean.com/bugfiles/slowrepro.zip. This contains the required NETPBM files. If these are already installed on your system, you can run the script below with slight modifications. Thanks, Nigel. ---- Repro: <? // Full repro kit including executables available from http://www.green-bean.com/bugfiles/slowrepro.zip // // Location of your NETPBM distribution // We're using http://prdownloads.sourceforge.net/gallery/netpbm1.1-gallery1.0-win32.tgz // $pbmroot = "netpbm"; // JPG input file (from http://www.green-bean.com/DallasChristmasHat.jpg) $file = "DallasChristmasHat.jpg"; function fs_exec($cmd, &$results, &$status, &$time) { // We can't redirect stderr with Windows. Hope that we won't need to. $time_st = time(); $x = exec("$cmd", $results, $status); $time = time() - $time_st; } $quiet = "-quiet"; // JPEG to PNM $cmd_to_pnm = "$pbmroot\\jpegtopnm $quiet $file > out\\$file.pnm"; print "<br>Exec: $cmd_to_pnm\n"; fs_exec($cmd_to_pnm, $results, $status, $elapsed); print "<br>Elapsed: $elapsed secs\n<br>Status: $status"; // PNM to scaled PNM $cmd_scale_pnm = "$pbmroot\\pnmscale $quiet -xysize 150 150 out\\$file.pnm > out\\$file.scale.pnm"; print "<br>Exec: $cmd_scale_pnm\n"; fs_exec($cmd_scale_pnm, $results, $status, $elapsed); print "<br>Elapsed: $elapsed secs\n<br>Status: $status"; // PNM scaled to JPG $cmd_to_jpg = "$pbmroot\\ppmtojpeg $quiet out\\$file.scale.pnm --quality=150 > out\\tn_$file"; print "<br>Exec: $cmd_to_jpg\n"; fs_exec($cmd_to_jpg, $results, $status, $elapsed); print "<br>Elapsed: $elapsed secs\n<br>Status: $status"; ?> PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 22:00:02 2025 UTC |
I don't know if anyone got any further (guessing not...) but I've taken the non-stable CVS snapshot, installed it, and modified the gallery script that makes an exec call to use proc_open. Unfortunatly it doesn't make any difference. The following (mess!) is the code I've used to test the call: $descriptorspec = array( 1 => array("pipe", "w") // stdout is a pipe that the child will write to // 2 => array("file", "/tmp/error-output.txt", "a"), // stderr is a file to write to ); msg("CALLING PROC_OPEN"); $process = proc_open("cmd.exe /c $cmd", $descriptorspec, $pipes); msg("PROC OPEN DONE"); if (is_resource($process)) { msg("SUCCESS"); // $pipes now looks like this: // 0 => writeable handle connected to child stdin // 1 => readable handle connected to child stdout // Any error output will be appended to /tmp/error-output.txt while(!feof($pipes[1])) { msg("+"); echo fgets($pipes[1], 2); msg("-"); } fclose($pipes[1]); $return_value = proc_close($process); echo "RETURNED: $return_value"; } Basically my output window does nothing for about 50 seconds after printing the first + symbol before the actual output from the command starts to appear. Running the identical command in a command prompt takes less than one second to complete. I'm running WinXP (home) with Apache 1.3.26 btw (and have the same problem people have reported above obviously).