note 95223 deleted from function.exec by danbrown

From: Date: Sat, 19 Dec 2009 16:28:24 +0000
Subject: note 95223 deleted from function.exec by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-164135@lists.php.net to get a copy of this message
Note Submitter: klaus dot wendel at lednew dot de ---- I had many problems with exec() in a program, rendering very large images and using some external tools via exec in a very performance and resources consuming process. Sometimes the program failed with "Warning: exec(): Unable to fork". In my case it definitely did not have to do with some process number limit to be set in /etc/security/limits.conf, as described in http://bugs.php.net/bug.php?id=18833&edit=3. Furthermore following workaround now does it very well: <?php function user_proc_exec ($command,& $result,& $status) { $process = proc_open( $command, array( 0 => array("pipe", "r"), //STDIN 1 => array("pipe", "w"), //STDOUT 2 => array("pipe","w")), //STDERR $pipes ); $result = stream_get_contents($pipes[1]); $error = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $status= proc_close($process); return($error); } ?> In most cases, exec() could simply be replaced by user_proc_exec(). However be aware, that user_proc_exec() does not return the last line of output as string, but the error message!

« previous php.notes (#164135) next »