Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:21647 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 9143 invoked by uid 1010); 23 Jan 2006 14:08:58 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 9128 invoked from network); 23 Jan 2006 14:08:58 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jan 2006 14:08:58 -0000 X-Host-Fingerprint: 64.233.184.203 wproxy.gmail.com Linux 2.4/2.6 Received: from ([64.233.184.203:31094] helo=wproxy.gmail.com) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id D4/BA-06819-A73E4D34 for ; Mon, 23 Jan 2006 09:08:58 -0500 Received: by wproxy.gmail.com with SMTP id i24so917372wra for ; Mon, 23 Jan 2006 06:08:55 -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=TpyedhddxnBGbt1wLLm9G+udgaZ9mZbsJrR4z9gyTia3B5NSoe7sGDJHqOWHNWi0rgGb33sc4TJMF5r/BMPClMkix8MBshDw02by+g/1OVS1k6AFoMfB5dQqzdf71SjIxf8Tzgf1hhpqxZbcm9X5ZdsphQnHZ2SmqliyDFwzVYc= Received: by 10.54.123.14 with SMTP id v14mr5793780wrc; Mon, 23 Jan 2006 06:08:55 -0800 (PST) Received: by 10.54.153.11 with HTTP; Mon, 23 Jan 2006 06:08:55 -0800 (PST) Message-ID: <4e89b4260601230608p18596cdchddcf0a460b79d37f@mail.gmail.com> Date: Mon, 23 Jan 2006 14:08:55 +0000 To: Mark Krenz Cc: internals@lists.php.net In-Reply-To: <20060123031050.GD23755@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> Subject: Re: [PHP-DEV] Fwd: [PHP] proc_open and buffer limit? From: kingwez@gmail.com (Wez Furlong) 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"; > }