pdftk를 사용하여 pdf 파일을 병합합니다. 사용자는 비정상적으로 형성된 PDF를 업로드하고 오류를 반환하지 않고 모든 서버 리소스를 사용하는 프로세스를 중단시킵니다. 이 문제를 방지하려면 proc_open
을 통해 프로세스 호출을 구현하는 중이고 시간 제한을 초과하면 프로세스를 실행하고 종료 할 시간 제한을 설정하고 싶습니다.x 초 후에 proc_open 종료
stream_set_blocking(): supplied resource is not a valid stream resource
내가 뭔가를 가정 : 다음
내가stream_set_blocking($process, 0);
설정은 오류를 반환하는 경우 PDF 파일을 병합 사용하고있는 함수의 예입니다 이 함수는 형식이 잘못되어 누군가가 올바른 방향으로 나를 가리킬 수 있기를 바랍니다 ... 함수는 현재 어떤 오류도 반환하지 않지만 필요에 따라 30 초 후에 종료하지 않습니다
protected function pdf_merge($documents,$output_file,$time = 30){
$end = time() + $time;
$cmd = sprintf('/usr/local/bin/pdftk %s cat output %s', $documents, $output_file);
$descriptorspec = array(
0 => array("pipe", "r"),
1 => array("pipe", "w"),
2 => array("file","./error.log","a")
);
$process = proc_open($cmd, $descriptorspec, $pipes);
if (is_resource($process)) {
stream_set_blocking($pipes[1], 0);
while (!feof($pipes[1]) && (time() < $end)) {
fwrite($pipes[0], stream_get_contents($pipes[0]));
fclose($pipes[0]);
$pdf_content = stream_get_contents($pipes[1]);
fclose($pipes[1]);
$return_value = proc_close($process);
return $return_value;
}
error_log('file is taking too long... kill process');
proc_terminate();
}
}
php.ini에서 'max_execution_time'? http://www.php.net/manual/en/info.configuration.php#ini.max-execution-time –
'proc_open()'으로 열린 파이프에서는'stream_set_blocking()'이 작동하지 않습니다 (https : /bugs.php.net/bug.php?id=47918) – naitsirch