Jump to content

500 Internal Server Error After 1 Minute


jebego

Recommended Posts

So, I have a php script that runs for a few minutes. It also parses lots of pages from other sites.

 

For some reason, after 60 seconds, I always get a 500 Internal Server Error. I thought it might be some php.ini problem, so I edited some values there:

max_execution_time = 1000

max_input_time = 1000

default_socket_timeout = 1000

memory_limit = 400M

post_max_size = 100M

file_uploads = On

upload_max_filesize = 100M

I also checked to see if these new settings occurred by creating a <?php phpinfo(); ?>, and this confirmed that they did take affect.

 

Unfortunately, this didn't change any of the problems, I'm still getting the 500 error.

 

At the end of my program, a file is created. Even when I shorten the program so that the creation doesn't run to see if this is the problem, I still get the 500 error. What's bizarre is that when I run the whole script, the file is still created, even after I get the error!

 

If I shorten the program to below 60 seconds, I don't get the error, but above, it appears.

 

Here's the piece of the program where the script is timed out (but continues running?):

for($j = 0; $j <= 11; $j ++){
if($color_counter[$j] != 0){
	if($j == 0){
		$color_string = "gray";
	}else if($j == 1){
		$color_string = "pink";
	}else if($j == 2){
		$color_string = "purple";
	}else if($j == 3){
		$color_string = "brown";
	}else if($j == 4){
		$color_string = "black";
	}else if($j == 5){
		$color_string = "blue";
	}else if($j == 6){
		$color_string = "green";
	}else if($j == 7){
		$color_string = "teal";
	}else if($j == {
		$color_string = "yellow";
	}else if($j == 9){
		$color_string = "orange";
	}else if($j == 10){
		$color_string = "red";
	}else if($j == 11){
		$color_string = "white";
	}
	$current = 0;
	$over_current = 0;
	for($page = 0; $page <= $color_counter[$j] / 21; $page ++){
		$str = file_get_contents("http://www.google.com/images?q=" . $keyword . "&hl=en&gbv=2&tbs=isch:1,ic:specific,isc:" . $color_string . "&source=lnt&start=" . ($page * 21) . "&ndsp=21");
		preg_match_all('/\["\/imgres.+?"","([a-zA-Z0-9-_]+\","(.+?)",".+?(t[0-9]\.gstatic\.com).+?""\]/', $str, $matches);
		if($color_counter[$j] - $current < 21){
			$temp = $current;
			for ($i = 0; $i <= $color_counter[$j] - $temp; $i++){
				if($current <= 800){
					$url_array_colors[$j][$current] = "http://" . $matches[3][$i] . "/images?q=tbn:" . $matches[1][$i] . $matches[2][$i];
				}else{
					$url_array_colors[$j][$current] = $url_array_colors[$j][$current - 800];
				}
				$current ++;
			}
		}else{
			for($i = 0; $i < 21; $i++) {
				if($current <= 800){
					$url_array_colors[$j][$current] = "http://" . $matches[3][$i] . "/images?q=tbn:" . $matches[1][$i] . $matches[2][$i];
				}else{
					$url_array_colors[$j][$current] = $url_array_colors[$j][$current - 800];
				}
				$current ++;
			}
		}
	}
}
}

 

Thanks for the help!

This probably won't help, but you can replace this "if/else if" block

<?php

	if($j == 0){
		$color_string = "gray";
	}else if($j == 1){
		$color_string = "pink";
	}else if($j == 2){
		$color_string = "purple";
	}else if($j == 3){
		$color_string = "brown";
	}else if($j == 4){
		$color_string = "black";
	}else if($j == 5){
		$color_string = "blue";
	}else if($j == 6){
		$color_string = "green";
	}else if($j == 7){
		$color_string = "teal";
	}else if($j == {
		$color_string = "yellow";
	}else if($j == 9){
		$color_string = "orange";
	}else if($j == 10){
		$color_string = "red";
	}else if($j == 11){
		$color_string = "white";
	}
?>

with

<?php
$colors = array('grey','pink','purple','brown','black','blue','green','teal','yellow','orange','red','white');
for($j = 0; $j <= 11; $j ++){
if($color_counter[$j] != 0){
                $color_string = $colors[$j];
//
// etc...
//
?>

 

Ken

I added the lines, but I'm still just getting the same error:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

 

Please contact the server administrator, [email protected] and inform them of the time the error occurred, and anything you might have done that may have caused the error.

 

More information about this error may be available in the server error log.

 

Apache/1.3.33 Server at xxxxxxxxx.com Port 80

 

Also, here's the error log for the 500 error

xxx.xx.xxx.xxx - - [04/Jun/2010:20:36:34 -0700] "GET xxxxxxxx.com/xxxx/xxxx/mosaic/image_merge.php HTTP/1.1" 500 616 "-" "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3 GTB7.0 ( .NET CLR 3.5.30729)"

 

Lastly, not sure if it's going to help, but I'm also having another strange problem with creating the file. After the 500 error appears, the file isn't instantly created, it takes 10 minutes for it to appear!

 

Is the script still running for another 10 minutes? O_o

 

Here's the last bit of code:

$image_name = microtime() . ".jpeg";
imagejpeg($final_image, "mosaics/" . $image_name);
imagedestroy($final_image);
header('Content-Type: image/jpeg; url="mosaics/" . $image_name');

 

Thanks again for your time!

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.