Questions tagged [php-stream-wrappers]

PHP provides a number of miscellaneous I/O streams that allow access to PHP's own input and output streams, the standard input, output and error file descriptors, in-memory and disk-backed temporary file streams, and filters that can manipulate other file resources as they are read from and written to.

PHP provides a number of miscellaneous I/O streams that allow access to PHP's own input and output streams, the standard input, output and error file descriptors, in-memory and disk-backed temporary file streams, and filters that can manipulate other file resources as they are read from and written to.

Some of the supported streams are:

  • php://stdin,
  • php://stdout
  • php://stderr
  • php://input
  • php://output
  • php://fd
  • php://memory
  • php://temp
  • php://filter
46 questions
26
votes
2 answers

What is a bucket brigade?

I would really love to implement a php_user_filter::filter(). But therefore I have to know what a bucket brigade is. This seems to be a resource which I can operate with the stream_bucket_* functions. But the documentation is not really helpful. The…
Markus Malkusch
  • 7,201
  • 35
  • 61
12
votes
3 answers

Create a stream from a resource

I know that I can create a PHP stream from a filename (a real one, or an URL), by using the fopen function: $stream = fopen('php://temp', 'r'); The resulting stream ($stream) is then a resource of type "stream", created from the URL php://temp. But…
dakis
  • 225
  • 1
  • 6
  • 32
7
votes
2 answers

php://input can only be read once in PHP 5.6.16

PHP manual states that a stream opened with php://input support seek operation and can be read multiple times as of PHP 5.6, but I can't make it work. The following example clearly shows it doesn't work:
gseric
  • 609
  • 4
  • 11
7
votes
2 answers

php stream_get_contents hangs at the end of the stream

Solution at the end of the question I am writing a PHP application that sends a message to a server and then reads a response back in using stream_get_contents. I communicate with the same server in an android app in the same way. The android app…
gb056
  • 149
  • 1
  • 7
5
votes
1 answer

How to use PSR-7 responses?

The majority of responses in my application are either views or JSON. I can't figure out how to put them in objects that implement ResponseInterface in PSR-7. Here is what I currently do: // Views header('Content-Type: text/html;…
rink.attendant.6
  • 36,468
  • 57
  • 89
  • 143
5
votes
3 answers

PHP: Writing a MYSQL query to CSV

I'm attempting to write a MySQLi query to a downloadable CSV. The following headers open a stream for the CSV: $fileName = ''; //empty file name, file name is cast later header("Cache=Control: must-revalidate, post-check=0,…
Liam Fell
  • 1,256
  • 2
  • 15
  • 32
4
votes
2 answers

PHP stream timeout if no data is transferred

I am currently implementing a PHP class that fetches image files and caches them locally. These images may come from other local sources, via HTTP or via HTTP using the Guzzle client. With PHP stream wrappers I should be able to handle all sources…
Mouagip
  • 4,560
  • 3
  • 34
  • 49
2
votes
0 answers

how to replace a string in a stream for very large files

How can I replace a string in a file that cannot be fully loaded into memory I can read it a few byes at a time, but how can I be sure I didn't read into the middle of my phrase? I think I should save the last strlen(phrase) length of bytes and try…
phper
  • 165
  • 1
  • 10
2
votes
0 answers

curl works, sockets fail for most domains and IPs

My local mac host is unable to use PHP's file stream wrappers in any form for HTTP requests (which is required to use composer, etc). If I request the exact same resource with the curl driver, everything is fine. Here's two programs I copied…
Incognito
  • 19,550
  • 15
  • 73
  • 117
2
votes
8 answers

File copied from a URL is truncated

I have a problem copying a file. My code: $file = "https://www.ilportaleofferte.it/portaleOfferte/resources/opendata/csv/offerteML/2019_1/PO_Offerte_G_MLIBERO_20190130.xml"; $newfile = $_SERVER['DOCUMENT_ROOT'] .…
illinois
  • 470
  • 1
  • 4
  • 16
2
votes
1 answer

How can I implement a PHP stream wrapper to modify the output of another wrapper?

I use the PHP zip:// stream wrapper to parse large XML files line by line. For example: $stream_uri = 'zip://' . __DIR__ . '/archive.zip#foo.xml'; $reader = new XMLReader(); $reader->open( $stream_uri, null ); $reader->read(); while ( true ) { …
And Finally
  • 5,190
  • 14
  • 63
  • 101
2
votes
1 answer

Using the zip:// wrapper for an archive with a single file whose name is unknown

PHP allows to read ZIP files on-the-fly with the zip:// wrapper: $fp = fopen ('zip://archive.zip#dir/file.txt', 'rb'); All good, when you know the compressed file name. This is not my case: my app has to deal with ZIP archives containing a single…
BenMorel
  • 30,280
  • 40
  • 163
  • 285
2
votes
0 answers

php://input reading is extreamly slow

I'm trying to write an API that accepts PUT, PATCH and DELETE request methods and I was able to do so, but I was running into an issue where reading from php://input is extremely slow. Parsing a request with a 970k gif file takes 10-12 seconds and…
SynackSA
  • 682
  • 9
  • 30
2
votes
2 answers

How to restrict file system access in PHP?

Someone knows a trick to have a PHP script self-restrict access to the file system (fopen, file_get_contents etc.)? Such calls should be blocked except for a handful of selected file names (log file, access to /tmp and similar). This is not a…
Udo G
  • 11,022
  • 11
  • 47
  • 77
1
vote
0 answers

How to pass options to stream_open in google cloud PHP stream wrapper

I'm trying to serve large audio files from google cloud storage with seeking support. I have difficulties understanding php fopen and google stream wrapper working together. When fopen is called it immediately calls stream_open from google…
Iko
  • 11
  • 1
1
2 3 4