simple_man_11 Posted February 20, 2007 Share Posted February 20, 2007 The following scripts runs great once I hit the button in the form. The problem is that if I close the browser it does not continue like I want it to. Does anyone know of a way to have this script run even if the browser is closed or not? <?php //get the current date $year = date("Y"); $month = date("m"); $day = date("d"); //start the ver for loop, will be removed later $number = 0; $usern=$_SESSION['username']; if($form == "true") { $reg= 1; } else { $reg = 0; } if($reg==1) { if(isset($_POST['Submit'])) { //NEED TO CHECK IF FIELDS ARE FILLED IN $ip = $_SERVER['REMOTE_ADDR']; $maincount = 0 ; $sendmail = 0; while ($maincount < 8 ) { echo " maincount: "; echo $maincount; echo " sendmail: "; echo $sendmail; echo " @ "; $now = date('h:i:s A'); echo $now; //connect to the db server include('config.php'); $query="select * from userEmail where eventM = '$month' and eventY = '$year' and eventD - '$day' <= 14 and reg = 'n' "; $result= mysql_query($query); $num=mysql_num_rows($result); if ($result) { while ($array= mysql_fetch_assoc($result)) { } $count = 0 ; // total of 8 hours (240 times IF SLEEP IS 120, 120 if sleep is 240) while ($count < 60 ) { echo " <br>"; echo " count: "; echo $count; echo " @ "; echo date('h:i:s A'); // sleep for 2 min (120) OR 4 MIN(240) sleep(120); $count++; } } else { if (@mysql_query ($query)) { //header("location:q2.php?reg=1"); $reg="1"; exit; } } mysql_close(); $maincount++; $sendmail++; } } else { echo " "; } } ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head><title>Auto reminder</title></head> <form name="form1" action="autoReminder2.php" method="post"> <div align="center"> <input name="form" type="hidden" value="true"> <table width="71%" border="0" bordercolor="#000000" height="64"> <tr> <td height="60" width="30%" valign="bottom"> <div align="center"> <p><input type="submit" name="Submit" value=" Start Scheduler "> </p> </div> </td> </tr> </table> <p>Copyright 2007 Auto Reminder Version 1.0</p> <p>Built by MidOhioIT.com </p> </div> </form> </html> Quote Link to comment Share on other sites More sharing options...
TEENFRONT Posted February 20, 2007 Share Posted February 20, 2007 You could use a CRON JOB to run the file at certain time intervals. Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted February 21, 2007 Author Share Posted February 21, 2007 I can not use cron because my server will not allow cron. Quote Link to comment Share on other sites More sharing options...
Jessica Posted February 21, 2007 Share Posted February 21, 2007 Get a decent host Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 I'm trying to understand the point of this script. While all of the above is true. If this script ran for 8 hours, it would most likely cause some problems. 1.) Your trying to hold a mysql connection open for an extended period of time. 2.) You won't have any session information held in a cron job. What are you trying to accomplish? Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted February 21, 2007 Author Share Posted February 21, 2007 I am trying to make this scripts completely automated instead of me having to rely on hitting the button on the form everyday or even better yet, my browser staying open. This script will hit the db and pull off people's email address and send them a reminder email 2 weeks prior to the event that they signed up for.. Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 There is a few options: 1) Cron job. Like everyone else has said (Best option) 2) Create an include file on a page of your site that gets visitors often. Have it simply check for ones that need to be sent, send them and go back to the user. (Bad idea, but none the less an option.) Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted February 21, 2007 Author Share Posted February 21, 2007 I dont know anything about Cron, can they start up my php script and tell it to execute? Quote Link to comment Share on other sites More sharing options...
trq Posted February 21, 2007 Share Posted February 21, 2007 can they start up my php script and tell it to execute? Yes, that is exactly what cron does. Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted February 21, 2007 Author Share Posted February 21, 2007 could someone please give me a screenshot from cpanel on setting one up to run my .php script at 9:00 am everyday? Quote Link to comment Share on other sites More sharing options...
AndyB Posted February 21, 2007 Share Posted February 21, 2007 Adjust 'acct' to your username, adjust yourfile.php to your script's name Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted February 21, 2007 Author Share Posted February 21, 2007 php /home/thesmi6/public_html/appointmentApp/autoReminder3.php >> /devl/null ...is what I put as the run command and added a log file to see how often the script would run. I changed the times for testing so I didnt have to wait until 9 am either. So far it is not updating the log, am I doing something wrong? Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 21, 2007 Share Posted February 21, 2007 take off the >> /dev/null for a minute and have the cron email you results. Then, see what's happening. Quote Link to comment Share on other sites More sharing options...
AndyB Posted February 21, 2007 Share Posted February 21, 2007 it's dev/null not devl/null Quote Link to comment Share on other sites More sharing options...
simple_man_11 Posted February 21, 2007 Author Share Posted February 21, 2007 It is working, thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.