Avatar of rgb192
rgb192
Flag 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
PHPLinux

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
Slimshaneey

Ray Paseur

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);
}
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
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Ray Paseur

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.
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

rgb192

ASKER
correction: with less rows in the form
the submit is more likely to process
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
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
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
rgb192

ASKER
i do not understand how to attach timer to submit code
Ray Paseur

The usage examples are in the timer script file.  Look near line 160.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
rgb192

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


thank you
Ray Paseur

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