I doubt if this can be done easily / efficiently, because php://temp (which is a
particular case of php://memory) has no particular file descriptor we can
watch for. At least until the memory limit specified for the stream is not
Well, we can make use of php_stream_temp_cast, which just makes a temporary file from the memory:
/* perform the conversion and then pass the request on to the innerstream */membuf=php_stream_memory_get_buffer(ts->innerstream,&memsize);file=php_stream_fopen_tmpfile();php_stream_write(file,membuf,memsize);pos=php_stream_tell(ts->innerstream);php_stream_free_enclosed(ts->innerstream,PHP_STREAM_FREE_CLOSE);ts->innerstream=file;php_stream_encloses(stream,ts->innerstream);php_stream_seek(ts->innerstream,pos,SEEK_SET);returnphp_stream_cast(ts->innerstream,castas,ret,1);
But is it sane? I'd rather make a regular file on tmpfs.
I may be wrong, but I still think this feature redundant. AFAIK, we've no enough control over the memory. We can listen to events on the "swap" file, but obviously it's not reasonable as we could use a regular file for that.