[PHP] I need ob_write($string, $start, $length)

2004-08-02 Thread jtl_phpdotnet
The guys in the internals list sent me to this forum.

I am trying to write some serious parsing software in PHP.  I need to use plain, 
vanilla PHP and no add-on modules, because I need to be able to distribute to people 
who don't have sufficient privileges.

In the process of parsing I create a new document composed of concatenated pieces of 
the original document.  I am efficiently catting the new document using output buffer, 
but when I have to copy non-contiguous pieces form the original document, I am forced 
to create substrings, as in:

echo substr($originalDoc, $startOfSnippet, $snippetLength)

My documents are potentially large with possibly thousands of such substrings.  I know 
from writing Java parsers for high-throughput servers that object creation, and in 
particular string creation, is the greatest source of degraded performance.

I'd like to copy the contents of a substring directly to the output buffer without 
creating an intermediate object, as in:

ob_write($string, $start, $length)

I can find no such function and could envision no other way to do this at present.

When can I expect broad support for such a function in the base PHP release?  Or do 
you know of a workaround?

BTW, because I had to ditch my last email address due to spam, I'm subscribed to this 
list through spamex.com.  But because the list makes the emails it distributes appear 
to original from the people who posted, I have no way to reply through spamex back to 
this forum, at least no way to keep the reply in the same thread.  Suggestions, are 
welcome.  Otherwise I'll be starting a new thread.

Thanks for your help!
~joe lapp

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Handles for multiple output buffers?

2004-08-02 Thread jtl_phpdotnet
Again, the internals list sent me to this forum for help.

In trying to create a series of parsers in PHP, using only PHP core and no 
non-standard add-ons, I find myself emulating multiple character streams in a class 
that wraps the output buffer.  Every time I open a new stream, I first save the 
current contents of the output buffer and then reset the stream.  When the stream is 
closed, I then restore the output buffer to what it was before.

I'd like more conventional 3GL behavior, where I am permitted multiple buffered 
streams via handles or stream objects.  I see no way to do this with PHP as it stands. 
 I also don't see anyway to emulate this without worsening the problem by creating a 
profusion of strings.

I'm mostly able to work around the performance inefficiences of this wrapper-class 
approach by making the application smart about when to use a new stream.  But I'd 
rather have native support.

When can I expect to see this kind of conventional stream behavior in PHP?  Are there 
any workaround I can use in the meantime?

Thanks for your help!

~joe

P.S.  Again, because this listserv sends emails to me as if they originated from the 
person who made the post, and because I'm now guarding my email address through 
spamex.com, I find that I am unable to respond directly to this thread.  My responses 
will likely appear in new a thread.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] I need ob_write($string, $start, $length)

2004-08-03 Thread jtl_phpdotnet
Hi Curt,

You could use a function of the name and signature you gave, but if you implement it 
in PHP, you're still creating the substring objects that I don't want created.  Notice 
your call to substr().  Object creation is expensive.  If the function were 
implemented natively, the language need only copy bytes directly from a portion of the 
source string over to the output buffer.

Thanks for taking a stab!
~joe

On 8/3/2004 Curt Zirzow wrote:
>I'm not entirely clear at what your trying to do but perhaps you
>want something like this:
>
>function print_substr_direct($string, $start, $len) {
>  static $fp = null;
>
>  if ($fp === null ) {
>// Open a connection directly to the output
>$fp = fopen('php://stdout', 'r');
>  }
>  if ($fp) {
>fputs($fp, substr($string, $start, $len));
>  }
>}

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Handles for multiple output buffers?

2004-08-03 Thread jtl_phpdotnet
Hi again Curt,

On 8/3/2004 Curt Zirzow wrote:
>You may be seeking: http://php.net/stream-wrapper-register
>
>With the example listed, you can have as many buffers as you
>please. 

Yeah, I could do what I'm already doing by implementing the interface you pointed me 
to.

The problem is that stdout appears to be the only in-memory buffered character stream 
available to me.  I need an abitrary number of such streams.

Emulating these streams, as one might do by implementing the interfaces you pointed me 
to, doesn't solve the problem; this is what I'm doing.  In my emulation I have to 
constantly cache and restore the contents of stdout.

Am I correct in saying that PHP only has this one in-memory buffered character stream? 
 (I need it to be in-memory because the goal is to maximize performance.)

Again, it's crucial that buffering be done natively by PHP, since otherwise you're 
just creating string objects that buffering is supposed to prevent you from having to 
create.

Thanks again for your suggestion!
~joe

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] I need ob_write($string, $start, $length)

2004-08-03 Thread jtl_phpdotnet
Another way to provide this ob_write() feature is to give me a start offset on 
fwrite(), as in:

fwrite($handle, $string, $length, $stringStartOffset)

~joe

P.S. I think I see why the internals group sent me here.  I didn't know about the 
handle-based stream functions, but looking over them they still don't address the 
problem.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php