PHP/resource/stream: Difference between revisions

from HTYP, the free directory anyone can edit if they can prove to me that they're not a spambot
No edit summary
No edit summary
 
Line 9: Line 9:
**** Maybe <code>{{l/pfx|PHP/fx/|feof}}()</code> would work? '''PROBLEM''': although docs say this can be used on a stream, they also say it has to have been opened with <code>{{l/pfx|PHP/fx/|fopen}}()</code> or <code>{{l/pfx|PHP/fx/|fsockopen}}()</code>, which rules out process-fed streams created with functions like <code>{{l/pfx|PHP/fx/|ssh2_exec}}()</code>.
**** Maybe <code>{{l/pfx|PHP/fx/|feof}}()</code> would work? '''PROBLEM''': although docs say this can be used on a stream, they also say it has to have been opened with <code>{{l/pfx|PHP/fx/|fopen}}()</code> or <code>{{l/pfx|PHP/fx/|fsockopen}}()</code>, which rules out process-fed streams created with functions like <code>{{l/pfx|PHP/fx/|ssh2_exec}}()</code>.
*** Does empty-string still correctly signal that the process has completed?
*** Does empty-string still correctly signal that the process has completed?
**** I ''think'' we have to assume that this is true for <code>{{l/pfx|PHP/fx/|stream_get_contents}}()</code>: it will never return empty as long as the process is active. (Maybe in non-blocking mode, it blocks until there is at least one byte, or something?)
*** What happens if the process has ''not'' completed (so there's no new data yet) -- how can we tell that there might be more?
*** What happens if the process has ''not'' completed (so there's no new data yet) -- how can we tell that there might be more?
==Links==
==Links==
===Official===
===Reference===
* [https://www.php.net/manual/en/ref.stream.php Stream Functions]
* [https://www.php.net/manual/en/ref.stream.php Stream Functions]

Latest revision as of 01:36, 11 February 2026

Template:Fmt/title

About

Although there are a lot of functions that handle streams in PHP, how to properly use these functions is often not explained very well. I'm having to reverse-engineer a lot through trial and error.

Tentative Conclusions

  • If a stream is set to blocking mode (with Template:L/pfx(Template:Arg, TRUE);), then EoS (end-of-stream) is indicated by the return of an empty string.
    • Questions about how it works in non-blocking mode:
      • How do we detect EoS in non-blocking mode? Some tentative leads:
      • Does empty-string still correctly signal that the process has completed?
        • I think we have to assume that this is true for Template:L/pfx(): it will never return empty as long as the process is active. (Maybe in non-blocking mode, it blocks until there is at least one byte, or something?)
      • What happens if the process has not completed (so there's no new data yet) -- how can we tell that there might be more?

Reference