user3297894
user3297894

Reputation: 61

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.

It works perfectly on an OVH VPS with Apache and PHP stanadard configuration standard. In other VPS to another provider with the same configuration, the same script stops downloading after 50 seconds.

And the browser (Chrome) reports unknown error of the network.

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.

Upvotes: 0

Views: 74

Answers (2)

user3297894
user3297894

Reputation: 61

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:

<?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');
?>

Upvotes: 0

Igor
Igor

Reputation: 178

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()

Upvotes: 1

Related Questions