DugoutSoccer
DugoutSoccer

Reputation: 422

PHP - Maximum Execution time of 30 seconds exceeded

sometimes I get the script execution error, where it takes over 30 seconds. It's always in my connector file. Could you have a look pelase and let me know if you say anything obvious...

I'm on a VPS so I have full control of the server so I can make any required changes.

session_start();
date_default_timezone_set('Europe/London');
$uTime = time();
$uDate = date('Ymd',$uTime);
$onlineLimit = 1800;
$activeLimit = 3628800;
$fDate = date('Ymd', strtotime('next monday'));
$time_start = microtime(true);

$db = mysql_connect("localhost", "xxxxxxx", "xxxxxxxx") or die("Could not connect.");
if(!$db) 
die("no db");
if(!mysql_select_db("xxxx",$db))
die("No database selected.");
if(!get_magic_quotes_gpc())
{
  $_GET = array_map('mysql_real_escape_string', $_GET); 
  $_POST = array_map('mysql_real_escape_string', $_POST); 
  $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
else
{  
   $_GET = array_map('stripslashes', $_GET); 
   $_POST = array_map('stripslashes', $_POST); 
   $_COOKIE = array_map('stripslashes', $_COOKIE);
   $_GET = array_map('mysql_real_escape_string', $_GET); 
   $_POST = array_map('mysql_real_escape_string', $_POST); 
   $_COOKIE = array_map('mysql_real_escape_string', $_COOKIE);
}
  mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'")or die(mysql_error());

  $page = $_SERVER['PHP_SELF'];
  $season = mysql_fetch_assoc(mysql_query("SELECT `id`,`start`,`end` from `season` order by `id` DESC limit 0,1"));
  $seasonDays = round((strtotime($season['end'])-strtotime($season['start'])) / 86400);
  $currentDay = ceil(($uTime - strtotime($season['start'])) / 86400);

Upvotes: 0

Views: 1819

Answers (3)

Patrick Lorio
Patrick Lorio

Reputation: 5668

add set_time_limit(0); to the top of your code, it will allow it to run without time constraints.

UPDATE to be safe as mentioned in the comments bellow set x in set_time_limit(x); to the max number of seconds of execution. 0 = infinite

Upvotes: 4

Luc Laverdure
Luc Laverdure

Reputation: 1480

You can also set it in a .htaccess file at the root of your site with:

php_value max_execution_time 3600

Upvotes: 0

anjalis
anjalis

Reputation: 397

i would set higher max_execution time in php.ini and you will see where it will die...

Upvotes: 3

Related Questions