Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21663 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78274 invoked by uid 1010); 24 Jan 2006 01:17:44 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 78259 invoked from network); 24 Jan 2006 01:17:43 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jan 2006 01:17:43 -0000 X-Host-Fingerprint: 64.233.184.201 wproxy.gmail.com Linux 2.4/2.6 Received: from ([64.233.184.201:29077] helo=wproxy.gmail.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 1F/82-06819-63085D34 for ; Mon, 23 Jan 2006 20:17:42 -0500 Received: by wproxy.gmail.com with SMTP id i24so1053683wra for ; Mon, 23 Jan 2006 17:17:39 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=LdYH5CRXKO3c4mrZDgNNuyGInCoVHUlr4uT5ohfN/PIHVFfd4l1jOsQK4ybJs95smCgFlA6mbTmLaa3OP6jZ5JajjbStLuqGsTN5Zo/fOH3ToYvH8F43s283qL5VJRpiwWIr+qRZCeD+lg0XP2I0zPI7zikdfyn7imabqGAw62M= Received: by 10.54.123.3 with SMTP id v3mr6287165wrc; Mon, 23 Jan 2006 17:17:39 -0800 (PST) Received: by 10.54.153.11 with HTTP; Mon, 23 Jan 2006 17:17:39 -0800 (PST) Message-ID: <4e89b4260601231717x40bdb6afid5b9fbcd4c019e2@mail.gmail.com> Date: Tue, 24 Jan 2006 01:17:39 +0000 To: Mark Krenz Cc: internals@lists.php.net In-Reply-To: <20060123163515.GB13342@arvo.suso.org> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20060123031050.GD23755@arvo.suso.org> <4e89b4260601230608p18596cdchddcf0a460b79d37f@mail.gmail.com> <20060123163515.GB13342@arvo.suso.org> Subject: Re: [PHP-DEV] Fwd: [PHP] proc_open and buffer limit? From: kingwez@gmail.com (Wez Furlong) I suggest running the script using strace: strace -e trace=3Dfile php myscript.php and taking a look to see what the underlying read/write syscalls are up to. --Wez. On 1/23/06, Mark Krenz wrote: > > Thanks for your help. stream_copy_to_stream does seem like a better > way to go. However I still have the same problem. Only 65536 bytes are > written to /tmp/output.txt. Here is the new source code based on your > ideas: > > -------------------------------------------------------------------------= - > $program =3D "/usr/bin/dd of=3D/tmp/output.txt"; > > $descriptorspec =3D array( > 0 =3D> array("pipe", "r"), > 1 =3D> array("pipe", "w"), > 2 =3D> array("file", "/tmp/error-output.txt", "a") > ); > > $cwd =3D '/var/www'; > $env =3D array('HOME' =3D> '/var/www'); > > $process =3D proc_open($program, $descriptorspec, $pipes, $cwd, $env); > > if (is_resource($process)) { > > stream_set_blocking($pipes[0], FALSE); > stream_set_blocking($pipes[1], FALSE); > > $handle =3D fopen("/usr/share/dict/words", "r"); > > stream_copy_to_stream($handle, $pipes[0]); > fclose($pipes[0]); > fclose($handle); > $output =3D stream_get_contents($pipes[1]); > fclose($pipes[1]); > > print "
$output


\n"; > > $return_value =3D proc_close($process); > > echo "command returned $return_value\n"; > } > -------------------------------------------------------------------------= - > > I switched to using dd instead of cat because using cat made the > situation more complex (because it sends back data as it gets it). The > program I'm going to eventually do this with doesn't do that. > > > On Mon, Jan 23, 2006 at 02:08:55PM GMT, Wez Furlong [kingwez@gmail.com] s= aid the following: > > There are quite a few bad streams usages there. > > > > I'd rewrite your code like this: > > > > $words =3D fopen('/usr/share/dict/words', 'r'); > > stream_copy_to_stream($words, $pipes[0]); > > fclose($pipes[0]); > > fclose($words); > > $output =3D stream_get_contents($pipes[1]); > > fclose($pipes[1]); > > proc_close($process); > > > > My guess at the cause of the problem was that you're tying to write > > 2MB into a pipe, and the underlying write() syscall could only write > > 64k; since you're ignoring the return code from fwrite(), you're > > missing this vital fact. > > > > Using the streams functions in PHP 5 helps you to write code that > > "does what I mean", and makes for shorter, more readable code. > > > > --Wez. > > > > PS: http://netevil.org/talks/PHP-Streams-Lucky-Dip.pdf > > has some tips and insider knowledge on using streams in PHP. > > > > > > > > On 1/23/06, Mark Krenz wrote: > > > stream_set_blocking($pipes[0], FALSE); > > > stream_set_blocking($pipes[1], FALSE); > > > > > > $handle =3D fopen("/usr/share/dict/words", "r"); > > > while (!feof($handle)) { > > > $input .=3D fread($handle, 8192); > > > } > > > > > > fwrite($pipes[0], $input); > > > fclose($handle); > > > fclose($pipes[0]); > > > > > > while (!feof($pipes[1])) { > > > $output .=3D fgets($pipes[1], 8192); > > > } > > > fclose($pipes[1]); > > > > > > print "
$output


\n"; > > > > > > $return_value =3D proc_close($process); > > > > > > echo "command returned $return_value\n"; > > > } > > > > > -- > Mark S. Krenz > IT Director > Suso Technology Services, Inc. > http://suso.org/ > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > >