Jump to content

script timing out on browser.


moola

Recommended Posts

Ok at least this is what I think my problem is:

I have a script that is being submited a post variable (or get variable) that works fine from my computer (on apache); but when I run it on my hosting server online it times out(stops exectuting halfway). I have tried the max_exectution_time and set_time_limit but it still quits on me. Does anyone have any clue what could be going on?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/37352-script-timing-out-on-browser/
Share on other sites

function remote_file_size ($url){ 
$head = ""; 
$url_p = parse_url($url); 
$host = $url_p["host"]; 
if(!preg_match("/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/",$host)){
	// a domain name was given, not an IP
	$ip=gethostbyname($host);
	if(!preg_match("/[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*/",$ip)){
		//domain could not be resolved
		return -1;
	}
}
$port = intval($url_p["port"]); 
if(!$port) $port=80;
$path = $url_p["path"]; 
//echo "Getting " . $host . ":" . $port . $path . " ...";

$fp = fsockopen($host, $port, $errno, $errstr, 20); 
if(!$fp) { 
	return false; 
	} else { 
	fputs($fp, "HEAD "  . $url  . " HTTP/1.1\r\n"); 
	fputs($fp, "HOST: " . $host . "\r\n"); 
	fputs($fp, "User-Agent: http://www.example.com/my_application\r\n");
	fputs($fp, "Connection: close\r\n\r\n"); 
	$headers = ""; 
	while (!feof($fp)) { 
		$headers .= fgets ($fp, 128); 
		} 
	} 
fclose ($fp); 
//echo $errno .": " . $errstr . "<br />";
$return = -2; 
$arr_headers = explode("\n", $headers); 
// echo "HTTP headers for <a href='" . $url . "'>..." . substr($url,strlen($url)-20). "</a>:";
// echo "<div class='http_headers'>";
foreach($arr_headers as $header) { 
	// if (trim($header)) echo trim($header) . "<br />";
	$s1 = "HTTP/1.1"; 
	$s2 = "Content-Length: "; 
	$s3 = "Location: "; 
	if(substr(strtolower ($header), 0, strlen($s1)) == strtolower($s1)) $status = substr($header, strlen($s1)); 
	if(substr(strtolower ($header), 0, strlen($s2)) == strtolower($s2)) $size   = substr($header, strlen($s2));  
	if(substr(strtolower ($header), 0, strlen($s3)) == strtolower($s3)) $newurl = substr($header, strlen($s3));  
	} 
// echo "</div>";
if(intval($size) > 0) {
	$return=intval($size);
} else {
	$return=$status;
}
// echo intval($status) .": [" . $newurl . "]<br />";
if (intval($status)==302 && strlen($newurl) > 0) {
	// 302 redirect: get HTTP HEAD of new URL
	$return=remote_file_size($newurl);
}
return $return; 
} 


for ($x = 0; $x < 200; $x++){

$url = a url link to video file;

$filesize = remote_file_size($url);

}

 

Is there an easier way to get the filesize of a remote file through url?

 

I tried getfilesize($content) // didn't work...

I've tried everything guys..

 

This may help:

 

I have a progress bar thing that works when index2.php is running on my localhost (apache server on my computer -> http://localhost/index2.php).

 

But when i'm running the script on example.com/index2.php, it won't show the progress "live"... it only runs for about 30 seconds on the browser (indicating that the page is loading) and then the end result is the output of index2.php (the progress bar). Whereas when its running on localhost/index2.php the progress bar is "live" (ie you see it progressing).

 

 

Why does it work on my localhost/index2.php ... but not on hosting server when i call example.com/index2.php?

 

* The script works perfectly and does what it is supposed to on my computer (apache) but on my hosting server (godaddy) it stops.

 

I have tried all php.ini settings. And I have tried a differed remote_file_size($url) function with curl.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.