Rajasekar
Rajasekar

Reputation: 18978

Is there any way to automatically run PHP script on Hosting web server withour cron?

I had a script which sends sms alerts everyday. I want it to send automatically send sms by fetching message from database. Can I do it without cron. Is there any other solution. Plz help

Upvotes: 4

Views: 7966

Answers (11)

user970258
user970258

Reputation: 21

Using third party webcron like easycron.com.

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382846

In simple words, you can't run php scripts without using some sort of scheduler or cron...

Upvotes: 3

Prez
Prez

Reputation: 11

you can include your script and have it run every time some one visits your homepage/login page etc... set up a table in mysql called time. query the database everytime the page is visited. if (time argument) {run the script in the background, update the new time in the DB}

All you have to do is fuigure out how often you want to send out your sms emails. Ex. 1 time per day database row "time" has a date in it. the date is lets say 24 hours ago. if the db row "time" is less than or equal to today minus one day 1 day , then run your script. this will run your script once per day.

The draw back -> someone needs to visit your site atleast once per day.

What is your website URL? What are you doing?

Upvotes: 1

Roch
Roch

Reputation: 22051

You can use a webcron service to trigger your script.

Upvotes: 3

Darren Newton
Darren Newton

Reputation: 2877

This isn't the best answer as it still requires cron somewhere, but you could always setup another machine that does have cron, like your home computer for instance, to hit a page on your site which triggers the action (using a library like curl or wget).

Upvotes: 0

Adam Dempsey
Adam Dempsey

Reputation: 2962

I've used windows Task Scheduler to schedule a script on a server I couldn't access cron on before, that worked fine.

Upvotes: 0

jldupont
jldupont

Reputation: 96826

Have an outside AppEngine cron job sheduler: Use google AppEngine, it's free. The outside "task" can then "callback" a PHP script of yours.

I fail to see what's wrong with using the local cron on your machine though aside from it being blocked for you to access.

Upvotes: 7

Mark Tomlin
Mark Tomlin

Reputation: 8943

It's not optimal, but without using any kind of scheduler what you could do is this.

  1. Setup a header file for each page.
  2. Within the header file put your function / procedure that you would like to run.
  3. Make an if statement that checks the if the time is greater then or equal too the time you need your procedure to run and that it has not already been run.

Down sides of this is that:

  1. There is no guaranteed time of service.
  2. If your website does not get hits, then it might miss the window completely.
  3. Your adding at least 3 function calls to your page, not to mention the function calls required to check if this processes was done today, that might include a call to a MySQL server or flat file ...

Upvotes: 0

code_burgar
code_burgar

Reputation: 12323

You have a couple of options:

  • Emulate cron behavior: In your php code, check if the page was loaded at, or close to, the time you wish to schedule the sendout for, if the messages havent been sent yet, load the script that sends the messages in the background and flag them as sent.

  • As others have suggested, setup a cronjob somewhere else that will execute a script on your server by fetching the url via http (by using wget for example)

Upvotes: 2

Matteo Riva
Matteo Riva

Reputation: 25060

If you can't set up a cron job on the server, do it on a client you have access to (like your computer) so that it does a request when you need the script to be run.

Upvotes: 0

just somebody
just somebody

Reputation: 19257

set up a cron task elsewhere, have it request the script that sends the alerts.

Upvotes: 1

Related Questions