Forum Moderators: coopster

Message Too Old, No Replies

making sendmail sleep()

putting sendmail to sleep

         

mc_gusto

1:25 am on Sep 27, 2007 (gmt 0)

10+ Year Member



Hi all,
I'm pretty new to PHP, and have been put on a rather large learning curve. I have an app that uses a general sendmail function that I would like to pause for a short amount of time before it emails users.

here is the code I propose to use:

<?PHP
sleep(29);
echo "Done\n";
?>

<?PHP
function sendmail($to,$from,$subject,$body){
$to="$to";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; ";
$headers.= "charset=iso-8859-1\r\n";
$headers.= "From: $from";
$subject = "$subject";

$body = "<HTML><BODY>
$body
</BODY></HTML>
";

mail($to,$subject,$body,$headers);
}
?>

Can you guys see any problems with just using the sleep function like this? would there be a better way to do it?
Also in anyones experience, would there be an issue of time outs with such a large number of seconds PHP is sleeping for, or can it go higher?

Thank you very much for any help or advice ^_^

mc_gusto

4:10 am on Sep 27, 2007 (gmt 0)

10+ Year Member



ok,
so I just answered my own silly little question ;P
The code I posted didn't work, but a slight alteration:

<?PHP
sleep(29);
echo "Done\n";
function sendmail($to,$from,$subject,$body){
$to="$to";
$headers.= "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; ";
$headers.= "charset=iso-8859-1\r\n";
$headers.= "From: $from";
$subject = "$subject";

$body = "<HTML><BODY>
$body
</BODY></HTML>
";

mail($to,$subject,$body,$headers);
}
?>

did end up working...
My question now is, how long is too long to make PHP sleep?
i.e. how long before I get timeouts and other such errors etc?

Once again, any help or advice is greatly appreciated ^_^

phparion

4:46 am on Sep 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you can set execution time with set_time_limit() [php.net]

I would suggest you to do a test before you use sleep() in your code.

Open firefox and open two tabs.
Open a youtube video in one page, while it is streaming, in the second tab run your sleep() script with a one minute interval.

ctrl+alt+delete and go to memory and cpu usage window

now check your system health as well as streaming video status and let me know if you feel anything strange with it.