Jump to content

[SOLVED] I need my scripts to run without using a browser..


simple_man_11

Recommended Posts

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>

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

cron2.jpg

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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