Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/rest/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP超时从中读取PUT数据php://input_Php_Rest_Timeout_Put - Fatal编程技术网

PHP超时从中读取PUT数据php://input

PHP超时从中读取PUT数据php://input,php,rest,timeout,put,Php,Rest,Timeout,Put,我创建了一个Restful API。 我可以从中读取PUT数据php://input,但我无法为此操作设置超时。如果读取PUT数据需要1秒以上,则应退出以下脚本。我还尝试了不同的方法,如“file_get_content”、“stream_get_contents”或为“max_input_time”设置不同的值,但如果脚本需要的时间比我设置的时间长,脚本不会停止 $handle = fopen("php://input", "r"); $timeout = 1; stream_set_tim

我创建了一个Restful API。 我可以从中读取PUT数据php://input,但我无法为此操作设置超时。如果读取PUT数据需要1秒以上,则应退出以下脚本。我还尝试了不同的方法,如“file_get_content”、“stream_get_contents”或为“max_input_time”设置不同的值,但如果脚本需要的时间比我设置的时间长,脚本不会停止

$handle = fopen("php://input", "r");
$timeout = 1;

stream_set_timeout($handle, $timeout);
stream_set_blocking($handle, true);

$info = stream_get_meta_data($handle);

$putData = "";

while (!feof($handle)) {
    if (($putData .= fgets($handle, 4096)) === false) {
        $info = stream_get_meta_data($handle);
    }
}

fclose($handle);

if ($info['timed_out']) {
    throw new \Exception("timeout");
}

不,我也读过这篇文章。我的最新代码与本文答案中的代码几乎没有什么不同。