Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

extend 30 second timeout without access to php.ini

hostgator shared lamp hosting
timeout of 30 seconds which can not be raised
processing a large form does a var_dump global

is there lines of php code I could put to keep a process running so no timeout as the form is submitting
Avatar of Slimshaneey
Slimshaneey
Flag of United Kingdom of Great Britain and Northern Ireland image

If they don't allow you to extend the timeout beyond 30 seconds, consider setting it repeatedly.  Rough example:

foreach ($thing...)
{
    /* DO SOMETHING */
    set_time_limit(29);
}
Avatar of rgb192

ASKER

this is a logged in page

while ($rowall = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
  set_time_limit(29);
echo $rowall['first_name']


and the page stops after 29 or 30 seconds and dumps the global variables


is there a way to add jquery or javascript or php so the php time limit is not reached
Well, I don't really know.  What does the query say?  I would bet it says SELECT * and does not have a LIMIT clause?

I can't figure out the part about "dumps the global variables."  What actually happens?  Can you show us an example?  Thanks.
Avatar of rgb192

ASKER

if I set a limit, I can create the form
so there is no timeout error with creating the form

but the timeout error occurs when I press submit  (even if there are only 50 rows in the form)

and after 30 seconds, all the post and global values are dumped to the screen


if(isset($_POST["submit"])){
  set_time_limit(29);
  //set variables to 0
    $q = 'update host_email set host_email_sent=0 where user_id=\''.$id.'\' and event_code_admins_id=\''.$eaid.'\';';    
     echo '<br>'.$q;
@mysqli_query ($dbc, $q);
  $url_block='';
  for ($counter=1;$counter<=6000;$counter++){
    $col_error[$counter].='';
 }

      /*echo '<pre>';
        print_r($_POST);
      echo '</pre>';
      exit;*/          
      echo '<h1>these emails have been sent:<h1>';
      foreach($_POST["selectedusers"] as $checkedUser){
        //email_template_id=29
     echo '<br>'.$checkedUser;        
     $q = 'update host_email set host_email_sent=1 where host_email_id=\''.$checkedUser.'\'';    
     //echo '<br>'.$q;
//$r = @mysqli_query ($dbc, $q); // Run the query. 


$qhostemailinfo='select * from host_email where host_email_id=\''.$checkedUser.'\' limit 0,1';
$rhostemailinfo=@mysqli_query ($dbc, $qhostemailinfo); // Run the query.

while ($rowhostemailinfo = mysqli_fetch_array($rhostemailinfo, MYSQLI_ASSOC)) {
  set_time_limit(30);
  //echo '<br>in loop: '.$inemailloop['user_id'];
  $guest_first_name=$rowhostemailinfo['host_email_first_name'];
  $guest_last_name=$rowhostemailinfo['host_email_last_name'];
  $guest_email=$rowhostemailinfo['host_email_email'];
  $guest_email_id=$rowhostemailinfo['host_email_id'];
  $col_error[$guest_email_id].='';
}
if ((empty($guest_first_name))||(empty($guest_last_name))){
$col_error[$guest_email_id].= '<p class="error">Please enter valid first name / last name</p>';
echo '<br>this is empty: '.$guest_first_name.' '.$guest_last_name;
}else{
    $q='
  insert into users(first_name, last_name,email,pass,active,user_level,source,registration_date,membership_type_id) values(\''.$guest_first_name.'\',\''.$guest_last_name.'\',
  \''.$guest_email.'\',
  \'11'.$guest_email_id.'\',
  \'111'.$guest_email_id.'\',
  \'4\',
  1,
  date_add(now(), interval 1 hour),
  24
  )
  ';
  echo '<br>'.$q;  
  //echo '<br>query'.$q;    
  /*$r = @*/mysqli_query ($dbc, $q);        
  //sleep(4);
  //echo '<br>last mysql id: '.mysqli_insert_id($dbc).'<br>';
  $last_insert_id=mysqli_insert_id($dbc);


  
  $q = 'update host_email set host_user_id='.$last_insert_id.' where host_email_id=\''.$checkedUser.'\'';    
     echo '<br>'.$q;
$r = @mysqli_query ($dbc, $q); // Run the query. 
  

$email_template_id=30;
  $q= 'insert into email(user_id,host_email_id,email_template_id,email_time,email_wait)values(,\''.$checkedUser.'\','.$email_template_id.',date_add(now(), interval 1 hour),1)'; 
  echo '<br>'.$q;
  $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
}//end empty update  
  
}//end foreach checked

//exit;
//foreach($col_error[$guest_email_id] as $value){
for ($counter=1;$counter<=6000;$counter++){
 if (!empty($col_error[$counter])){
  echo '<br>value: '.$counter;
  $url_block=$counter;
 }
}
//exit();
if (empty($url_block)){
$url='successful.php';

header('Location: '. $url);
  echo'
<script type="text/javascript">
<!--
window.location = "'.$url.'"
//-->
</script>   
';      
}      
      
}//end submit

Open in new window

Avatar of rgb192

ASKER

correction: with less rows in the form
the submit is more likely to process
Avatar of rgb192

ASKER

i disabled the inserts and updates
I have 1000 rows to process in submit form
works when I do 400 rows but gets 500 error or var_dumps global values if timeout time exceeds 30 seconds

if(isset($_POST["submit"])){
  set_time_limit(30);
  //set variables to 0
    $q = 'update host_email set host_email_sent=0 where user_id=\''.$id.'\' and event_code_admins_id=\''.$eaid.'\';';    
     echo '<br>'.$q;
//@mysqli_query ($dbc, $q);
  $url_block='';
 /* for ($counter=1;$counter<=6000;$counter++){
    $col_error[$counter].='';
 }*/

      /*echo '<pre>';
        print_r($_POST);
      echo '</pre>';
      exit;*/          
      echo '<h1>these emails have been sent:<h1>';
      foreach($_POST["selectedusers"] as $checkedUser){
        $col_error[$checkedUser].='';
        //email_template_id=29
     echo '<br>'.$checkedUser;        
     $q = 'update host_email set host_email_sent=1 where host_email_id=\''.$checkedUser.'\'';    
     //echo '<br>'.$q;
//$r = @mysqli_query ($dbc, $q); // Run the query. 


$qhostemailinfo='select * from host_email where host_email_id=\''.$checkedUser.'\' limit 0,1';
$rhostemailinfo=@mysqli_query ($dbc, $qhostemailinfo); // Run the query.

while ($rowhostemailinfo = mysqli_fetch_array($rhostemailinfo, MYSQLI_ASSOC)) {
  set_time_limit(30);
  //echo '<br>in loop: '.$inemailloop['user_id'];
  $guest_first_name=$rowhostemailinfo['host_email_first_name'];
  $guest_last_name=$rowhostemailinfo['host_email_last_name'];
  $guest_email=$rowhostemailinfo['host_email_email'];
  $guest_email_id=$rowhostemailinfo['host_email_id'];
  $col_error[$guest_email_id].='';
}
if ((empty($guest_first_name))||(empty($guest_last_name))){
$col_error[$guest_email_id].= '<p class="error">Please enter valid first name / last name</p>';
echo '<br>this is empty: '.$guest_first_name.' '.$guest_last_name;
}else{
    $q='
  insert into users(first_name, last_name,email,pass,active,user_level,source,registration_date,membership_type_id) values(\''.$guest_first_name.'\',\''.$guest_last_name.'\',
  \''.$guest_email.'\',
  \'11'.$guest_email_id.'\',
  \'111'.$guest_email_id.'\',
  \'4\',
  1,
  date_add(now(), interval 1 hour),
  24
  )
  ';
  echo '<br>'.$q;  
  //echo '<br>query'.$q;    
  /*$r = @*///mysqli_query ($dbc, $q);        
  //sleep(4);
  //echo '<br>last mysql id: '.mysqli_insert_id($dbc).'<br>';
  //$last_insert_id=mysqli_insert_id($dbc);


  
  $q = 'update host_email set host_user_id='.$last_insert_id.' where host_email_id=\''.$checkedUser.'\'';    
     echo '<br>'.$q;
//$r = @mysqli_query ($dbc, $q); // Run the query. 
  

$email_template_id=30;
  $q= 'insert into email(user_id,host_email_id,email_template_id,email_time,email_wait)values(,\''.$checkedUser.'\','.$email_template_id.',date_add(now(), interval 1 hour),1)'; 
  echo '<br>'.$q;
 // $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
}//end empty update  
  
}//end foreach checked

//exit;
//foreach($col_error[$guest_email_id] as $value){
foreach ($_POST["selectedusers"] as $checkedUser){
 if (!empty($col_error[$checkedUser])){
  echo '<br>value: '.$checkedUser;
  $url_block=$checkedUser;
 }
}
//exit();
if (empty($url_block)){
$url='success.php';

header('Location: '. $url);
  echo'
<script type="text/javascript">
<!--
window.location = "'.$url.'"
//-->
</script>   
';      
}      
      
}//end submit

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

i do not understand how to attach timer to submit code
The usage examples are in the timer script file.  Look near line 160.
Avatar of rgb192

ASKER

this shows load time of pages
and will help me debug the bottleneck in webpages


thank you
Thanks for the points.  I hope it helps you find the bottlenecks! ~Ray