Jump to content

Time Out stopping my PHP / Shell script


darcyf1.com

Recommended Posts

I have searched everywhere and asked quite a few people and got no where.

 

I have a script running that gets a certain set of files (info retrieved from mysql database) and then executes a shell command that zips them all into a zip file for easy download.

 

THE PROBLEM!

Sometimes the collection of files (videos in this case) can be quite large.

Running the shell command to zip such large files can take up to 10mins for 2GB and runs successfully. [i am not looking at collections quite that big for my script]

 

When I try to call this command during the php, it runs for a little more than 30 seconds, and if it hasn't finished by then, it fails and I am returned an 'Internal Error Page'.

If the command does finish, then the script works perfectly well.

 

I have tried things like playing around with;

set_time_limit, max_execution_time, max_input_time etc.

I do not have direct access to php.ini (as I am hosting with a company).

 

Any suggestions would be greatly appreciated!!

 

<?php
set_time_limit(0);

$files = "";
$count = 0;
$nameofzip = "$race"; $nameofzip .= "$season"; $nameofzip .= ".darcyf1.zip"; 
$con = mysql_connect("$address","$user","$password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("$table_name", $con);
$sql = "SELECT * FROM clips WHERE (Cat='$series') AND (Season='$season') AND (Race='$race') AND Full IS NULL";
$result = mysql_query($sql);
if($row = mysql_fetch_array($result)){
	 do {
	 $files .= "{$row["Link"]} ";
	 $count = $count + 1;
	 } while ($row = mysql_fetch_array($result));
}
mysql_free_result($result);

shell_exec("zip $nameofzip $files;");
echo "<br /><strong>$count files zipped - <a href='../go.php?c=$series&f=$nameofzip'>Download</a></strong>";
}

?>

 

I repeat, the code works perfectly if the command doesn't take too long!

 

Thanks,

Darcy!

Link to comment
https://forums.phpfreaks.com/topic/169737-time-out-stopping-my-php-shell-script/
Share on other sites

Your web server probably also has a timeout value, but if scripts really do take a long time to execute, you should probably consider running them from the command line or via a cron task

 

But how would I go about doing that?

I can run the command manually, but I can't sit there all day waiting for requests to come in, and then I assemble the zip file manually.

I'm all out of ideas :S

  • 2 weeks later...

I have the same problem. The cron jobs are heavy and take a long time to execute sometimes, and I have used

 

set_time_limit to 300 while the cron jobs are set to 5 minutes interval. Sometimes when the crons take too long to execute the cron jobs stop completely without sending any mails or the subsequent crons executing.

 

I am in a lot of pain because of this, added with the 500 internal server error pages that come up when these crons stop executing sometimes.

 

Please help somebody.

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.