Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:9894 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 85347 invoked by uid 1010); 17 May 2004 15:36:41 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 85296 invoked from network); 17 May 2004 15:36:40 -0000 Received: from unknown (HELO pigeon.alphaweb.net) (64.142.6.229) by pb1.pair.com with SMTP; 17 May 2004 15:36:40 -0000 Received: from alphaweb.net ([64.142.6.229] helo=basillica) by pigeon.alphaweb.net with smtp (Exim 4.10) id 1BPlKB-0007QK-00; Mon, 17 May 2004 09:50:47 -0700 Message-ID: <010401c43c24$f73a5160$de00000a@alphaweb.net> To: "Ben Chivers" Cc: References: <20040517140903.89926.qmail@pb1.pair.com> Date: Mon, 17 May 2004 08:37:58 -0700 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Subject: Re: Streams - Extensions From: pollita@php.net ("Sara Golemon") Two things: (1) If all you're doing is outputting, go for php_printf() rather than the php://stdout or php://output stream. It avoids the need to open additional streams and makes sure that your extension won't have problems compiling against pre-4.3 versions of PHP. (2) You've got code defined as char[128], and use sizeof() in your php_stream_write() call which means that you'll wind up outputting the entire 128 bytes of the char array, plus you don't want the trailing NULL anyway, so go with strlen() rather than sizeof() here. That said, the most universal way of retrieving data otherwise output by PHP is through output buffering. Recall that in userspace you can do ob_start(); /* do stuff */ $contents = ob_get_contents(); ob_end_clean(); To get the output of the /* do stuff */ block into $contents. In C-land you can take the equivalent approach, or temporarily override the output handler, but I recommend the ob approach as it's a bit easier. Take a look in main/ouput.c for the internal implemetation of the ob_*() functions. -Sara ----- Original Message ----- From: "Ben Chivers" Newsgroups: php.internals To: Sent: Monday, May 17, 2004 7:07 AM Subject: Re: Streams - Extensions > Hi, > > I've been looking at the PHP streams source code. I wondered if you could > help with this problem i've got with a PHP extension. Any help with this > would be very much appreciated! > > What I want to do is create a php extension which parses php code to the > interpreter. e.g. the php script using the php extension will something > like this: > > > passCode("echo('Hello World');"); > > ?> > > The extension will look something like this: > > PHP_FUNCTION > { > char code[128] = "echo('Hello World');"; > size_t bt; > > php_stream * phpStream = php_stream_open_wrapper("php://stdout", "w", > REPORT_ERRORS, NULL); > if (stream) > { > zend_printf("Stream Connected"); > bt = php_stream_write(phpStream, code, sizeof(code)); > php_stream_close(phpStream); > } > else > { > zend_printf("Stream Connection Error"); > } > } > > This function would pass the code "echo('Hello World');" to PHP and execute > it. What I am having problems is, is retrieving the output of this function > e.g. "Hello World". But the problem with PHP is that it's unidirectional > (oneway) from what I know. > > Is there a way to read the output from PHP? What would be the best way of > doing that? Would it have anything to do with flushing? > > Thank you very much for your time. Any help with this would be most > appreciated. I wanted to ask you, as you are a developer for PHP, and you > developed the php streaming for php extensions and c++ programs. > > I hope it makes sense. > > Many Regards, > Ben Chivers > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.686 / Virus Database: 447 - Release Date: 14/05/2004