execute a php script without a cron job?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

execute a php script without a cron job?

Post by SmokyBarnable »

I had a small php program that checked my email via cron job every 60 seconds. My isp just told me I can't do it that often. Is there any way to have a php script run forever on a server without a cron job?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

How about setting it to a slower pace so that it doesn't upset your host?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

set_time_limit(0);
ignore_user_abort(1);

while(1)
{
   // Yay I will never end unless you kill the process!! 
   
   //sleep sleep for 60 seconds
   sleep(60);
}
If your feeling adventurous. I'm not sure how this will affect your server performance though.. likely horribly.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

8O

Somewhere, a sysadmin is screaming "JCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAARRRRRRRRRRRRRRRRRRRRRRRRRRRT!!!!!!!"
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

Download...

http://www.bitfolge.de/pseudocron-en.html

And then add...

something like this

Code: Select all

include ("pseudo-cron/pseudo-cron.inc.php");
to every page on your website.

But then again now that I think about it you are doing something really strange.

Why aren't you using an email client that checks your email every second instead of doing it on the server?
User avatar
SmokyBarnable
Forum Contributor
Posts: 105
Joined: Wed Nov 01, 2006 5:44 pm

Post by SmokyBarnable »

Why aren't you using an email client that checks your email every second instead of doing it on the server?
It just checks to see if any of my ebay auctions have any new sales and then sends an end of auction email to the bidder. I would do it with the above method but ebay limits the amount of api calls you can have per month. So parsing end of auction emails was the only way I could figure to trigger an api call.....but my isp didn't like it much.
User avatar
AKA Panama Jack
Forum Regular
Posts: 878
Joined: Mon Nov 14, 2005 4:21 pm

Post by AKA Panama Jack »

SmokyBarnable wrote:
Why aren't you using an email client that checks your email every second instead of doing it on the server?
It just checks to see if any of my ebay auctions have any new sales and then sends an end of auction email to the bidder. I would do it with the above method but ebay limits the amount of api calls you can have per month. So parsing end of auction emails was the only way I could figure to trigger an api call.....but my isp didn't like it much.
Then why don't you just process them once every 30 minutes? That should be soon enough and most hosting companies that have limits on how often cron tasks can be run allow that.
Post Reply