note 95223 added to function.exec

From: Date: Sat, 19 Dec 2009 12:38:21 +0000
Subject: note 95223 added to function.exec
Groups: php.notes 
Request: Send a blank email to php-notes+get-164133@lists.php.net to get a copy of this message
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! ---- Server IP: 212.124.37.9 Probable Submitter: 91.22.167.1 ---- Manual Page -- http://www.php.net/manual/en/function.exec.php Edit -- https://master.php.net/note/edit/95223 Del: integrated -- https://master.php.net/note/delete/95223/integrated Del: useless -- https://master.php.net/note/delete/95223/useless Del: bad code -- https://master.php.net/note/delete/95223/bad+code Del: spam -- https://master.php.net/note/delete/95223/spam Del: non-english -- https://master.php.net/note/delete/95223/non-english Del: in docs -- https://master.php.net/note/delete/95223/in+docs Del: other reasons-- https://master.php.net/note/delete/95223 Reject -- https://master.php.net/note/reject/95223 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164133) next »