简体   繁体   English

Apache停止脚本

[英]Apache stops the script

I have a problem with a PHP script allows download files outside of the site, directly on the pc of the user. 我有一个PHP脚本问题,该脚本允许直接在用户PC上在网站外部下载文件。

It works perfectly on an OVH VPS with Apache and PHP stanadard configuration standard. 它在具有Apache和PHP stanadard配置标准的OVH VPS上完美运行。 In other VPS to another provider with the same configuration, the same script stops downloading after 50 seconds. 在其他具有相同配置的提供商的VPS中,相同的脚本会在50秒后停止下载。

And the browser (Chrome) reports unknown error of the network. 并且浏览器(Chrome)报告了未知的网络错误。

I tried to set set_time_limit(0) in the script, but it does't work, I changed the timeout in the php.ini , but still does not work, ask for help to understand what can depend this. 我试图在脚本中设置set_time_limit(0) ,但是它不起作用,我在php.ini更改了超时,但是仍然不起作用,请寻求帮助以了解可以依赖此的内容。

You've changed parameter that manages time of execution of script, but you need to change parameter that responsible for time needed for parsing request data. 您已经更改了用于管理脚本执行时间的参数,但是您需要更改负责解析请求数据所需时间的参数。 It's max_input_time - so you can change it in php.ini or via function ini_set() 它是max_input_time因此您可以在php.ini或通过函数ini_set()进行更改

I have also tried to set max_input_time to 120 or higher, and even to 0, but the problem remains the same, on the other vps max_input_time is set to 60 and everything works normally This Is my php: 我也尝试将max_input_time设置为120或更高,甚至设置为0,但问题仍然相同,在另一个vps上,max_input_time设置为60,并且一切正常,这是我的php:

<?php
set_time_limit(0);
function get_size($url) {
$my_ch = curl_init();
curl_setopt($my_ch, CURLOPT_URL,$url);
curl_setopt($my_ch, CURLOPT_HEADER, true);
curl_setopt($my_ch, CURLOPT_NOBODY, true);
curl_setopt($my_ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($my_ch, CURLOPT_TIMEOUT, 35);
$r = curl_exec($my_ch);
foreach(explode("\n", $r) as $header) {
    if(strpos($header, 'Content-Length:') === 0) {
        return trim(substr($header,16));
    }
}
return '';
}

$url=base64_decode(filter_var($_GET['url']));
$name =($_GET['title']);
$size=get_size($url);
//echo $url."<br>".$size;

// Fetch and serve
if ($url)
{
$size=get_size($url);
// Generate the server headers
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
{
header('Content-Type: application/octet-string');
header('Content-Disposition: attachment; filename="' . $name . '"');
header('Expires: 0');
header('Content-Length: '.$size);
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header("Content-Transfer-Encoding: binary");
header('Pragma: public');
}
else
{
header('Content-Type: application/octet-string');
header('Content-Disposition: attachment; filename="' . $name . '"');
header("Content-Transfer-Encoding: binary");
header('Expires: 0');
header('Content-Length: '.$size);
header('Pragma: no-cache');
}

readfile($url);
exit;
}

//Not found;
exit('File not found');
?>

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

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