【发布时间】:2012-02-28 23:50:34
【问题描述】:
在一个 php 文件中,我正在读取包含图像的输入流。
$incomingData = file_get_contents('php://input');
$fh = fopen($uploadPath, 'w');
fwrite($fh, $incomingData);
fclose($fh);
对于小图像,这工作得很好,对于需要超过 15 秒左右的大图像,我得到 502 bad gateway 响应。
apache 错误日志说:
child pid 1492 exit signal Segmentation fault (11)
我试过了,但是没有用。
ini_set('default_socket_timeout', 120);
但我不确定它是否超时。
编辑// 代码:
$uploadFilename = time();
$uploadPath = '/path/melvin.jpg';
$fhSrc = fopen('php://input', 'r');
// Valid data?
if($fhSrc) {
$fhDst = fopen($uploadPath, 'w');
while (($data = fread($fhSrc, 1024)) !== FALSE) {
fwrite($fhDst, $data);
}
fclose($fhSrc);
fclose($fhDst);
}
echo 'ok';
原始标题:
POST /test.php HTTP/1.1
Host: hi.com
User-Agent: secret/1.0 (unknown, iPhone OS 5.0.1, iPhone, Scale/2.000000)
Accept: */*
Accept-Language: nl, en, fr, de, ja, it, es, pt, pt-PT, da, fi, nb, sv, ko, zh-Hans, zh-Hant, ru, pl, tr, uk, ar, hr, cs, el, he, ro, sk, th, id, ms, en-GB, ca, hu, vi, en-us;q=0.8
Accept-Encoding: gzip
Settings: {SOMEJSON}
Content-Type: application/x-www-form-urlencoded
Cookie: CAKEPHP=2b82f748fb3a64063b2e3be9bdec5c11
Connection: keep-alive
Transfer-Encoding: Chunked
Pragma: no-cache
Cache-Control: no-cache
and here in the boy the Big image
【问题讨论】:
-
set_time_limit()有帮助吗? -
检查 php 错误日志。我认为您正在达到内存限制,因为您将图像缓冲成字符串。无论如何,更有效的方法是
copy('php://input', $destination); -
不,max_input_time() 或 max_execution_time() 也没有
-
@chris copy() 确实有效,但给出了完全相同的问题。还有其他解决方案吗?与此同时,当我试图阅读我的 php 错误日志时。