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 3: Line 3:
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.
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==
==Tentative Conclusions==
* If a stream is set to blocking mode (with <code>[https://www.php.net/manual/en/function.stream-set-blocking.php stream_set_blocking]({{arg|stream resource}}, TRUE);</code>), then EoS (end-of-stream) is indicated by the return of an empty string.
* If a stream is set to blocking mode (with <code>{{l/pfx|PHP/fx/|stream_set_blocking}}({{arg|stream resource}}, TRUE);</code>), then EoS (end-of-stream) is indicated by the return of an empty string.
** Questions about how it works in non-blocking mode:
** Questions about how it works in non-blocking mode:
*** How do we detect EoS in ''non''-blocking mode?
*** How do we detect EoS in ''non''-blocking mode?
**** [https://www.php.net/manual/en/stream.constants.php#constant.stream-notify-completed STREAM_NOTIFY_COMPLETED] (as used by [https://www.php.net/manual/en/function.stream-notification-callback.php <code>stream_notification_callback()</code>]) seems possibly relevant here.
**** [https://www.php.net/manual/en/stream.constants.php#constant.stream-notify-completed STREAM_NOTIFY_COMPLETED] (as used by <code>{{l/pfx|PHP/fx/|stream_notification_callback}}()</code>) seems possibly relevant here.
*** Does empty-string still correctly signal that the process has completed?
*** Does empty-string still correctly signal that the process has completed?
*** 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?

Revision as of 18:03, 10 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?
      • Does empty-string still correctly signal that the process has completed?
      • What happens if the process has not completed (so there's no new data yet) -- how can we tell that there might be more?

Official