Hi Guys,
I have a question about PHP and Ajax/Javascript SetInterval.

Im working on an application that users will be able to subscribe to and I want
an email sent to them after !exactly 24 hrs. The only way that I could think of doing
something like this is by creating an interval that will execute an Ajax function that will call a php function that compares the user subscription timestamp to the current timestamp and if it's greater than 24 hrs it will send the email.

The application is working fine, but I just realized that when the browser is closed,
the SetInterval functions stop working?! I thought that after executing it once it will keep working on the server but I was wrong... I tried to create a simple application that uses php/ajax and logs the current timestamp every 3 seconds into a txt file, again it's working fine but only when the browser page that have the script on is open!

Is there a way to create an interval that keeps working on the server without anyone viewing the page that calls the function ?

Thanks

Recommended Answers

All 2 Replies

You need cronjob dear.
In cronjob you can set php file name and time interval that will execute that php file.
e.g. you have sendnewsletter.php and set time 'every night 12am'.
Server will call that file daily at 12am, thats it.. all is done.

Cronjob setting is in server's hosting panel.
See this link http://www.siteground.com/tutorials/cpanel/cron_jobs.htm for guidance.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.