我使用 stream_context_create
和 fopen
通过 PHP 发送数据(POST 方法)。
$opts['http']['content']
工作得很好,但我现在需要发送一个非常大的文件(无法在内存中分配)。
有没有办法告诉 PHP 内容
是一个流?
例如$opts['http']['content'] = fopen("/tmp/bigfile.bin");
是否可以使用其他方法(不使用curl)来仍然使用stream_context_create
?
最佳答案
您可以使用fsockopen
代替。
阅读手册http://www.php.net/manual/en/function.fsockopen.php
通过这种方式,您可以使用 fwrite
( http://www.php.net/manual/en/function.fwrite.php ) 按 block 发送数据。
但是您必须手动编写 HTTP header 才能将其与 Web 服务器一起使用。
关于php - 使用php发布大数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17041725/