简体   繁体   English

PHP随机中断

[英]PHP randomly cuts off

I've made a VERY basic website which takes an array of image URLs, zips them, and returns the zip location. 我已经建立了一个非常基础的网站,该网站接受一系列图像URL,将其压缩并返回zip位置。 The problem is that the script cuts off at some point. 问题是该脚本在某个时间点中断。

One of the following usually happens: 通常发生以下情况之一:

  • not all the pictures are copied 并非所有图片都被复制
  • not all pictures are copied and the last picture has 0 file size 并非所有照片都被复制并且最后一张照片的文件大小为0
  • sometimes the ajax call doesn't run the error or success callback 有时ajax调用不会运行错误或成功回调

Is this because the server is only allowing a certain amount of time for the script to execute? 这是因为服务器仅允许脚本执行一定时间吗? It does seem to work with less pictures. 它似乎可以用更少的图片工作。 What can I do? 我能做什么?

I have the following settings: 我有以下设置:

  • max_execution_time 10 max_execution_time 10
  • max_file_uploads 20 max_file_uploads 20
  • max_input_nesting_level 64 max_input_nesting_level 64
  • max_input_time 10 max_input_time 10

also, set_time_limit is disabled. 同样,set_time_limit被禁用。

I tried ini_set('max_execution_time', 300); 我尝试过ini_set('max_execution_time',300); and nothing changed 并没有改变

edit: Probably a REALLY stupid question, but would it change anything if I executed another PHP page after a certain amount of time if the script isn't going to finish before the limit? 编辑:这可能是一个非常愚蠢的问题,但是如果脚本在限制之前没有完成,如果在一定时间后执行了另一个PHP页面,它会更改任何内容吗?

I'm using: 我正在使用:

<?php
    include('zip2.php');
    header("content-type: text/javascript"); 


    function err($que){
        $obj->err = $que;
        echo $_GET['callback']. '(' . json_encode($obj) . ');';
        die;
        }
    if(!count($_GET['pictures'])>0){die;}
    $tmpp = tempnam('userzips','mod');
    unlink($tmpp);
    $loc = 'userzips/'.basename($tmpp);
    mkdir($loc);
    $a=$_GET['pictures'];
    for($i=0;$i<count($a);$i++){
        copy($a[$i],$loc.'/'.basename($a[$i])) or err("didn't zip");
        }
    Zip($loc,$loc.'/pictures.zip') or err("didn't zip");
    $obj->loc = 'http://mysite.com/'.$loc.'/pictures.zip';
    $obj->allgood = true;
    echo $_GET['callback']. '(' . json_encode($obj) . ');';

?>

IT WILL SOMETIMES work and sometimes not for the same input. 它有时可能会工作,有时可能不会使用相同的输入。 This is what really gets me. 这才真正让我受益。

upload_max_filesize and post_max_size also can be reason upload_max_filesize和post_max_size也可能是原因

upload_max_filesize=100M
post_max_size=105M
max_execution_time=600
max_input_time=600

try to check errors while copy 尝试在复制时检查错误

if(!@copy('http://someserver.com/somefile.zip','./somefile.zip'))
{
    $errors= error_get_last();
    echo "COPY ERROR: ".$errors['type'];
    echo "<br />\n".$errors['message'];
} else {
    echo "File copied from remote!";
}

also I heard that there are some problems with copy when url have spaces 我也听说URL有空格时复制有一些问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM