Connecting Tech Pros Worldwide Help | Site Map

Cron Job

Member
 
Join Date: Feb 2008
Posts: 50
#1: Mar 31 '08
I have a question :
I m using window host and i dont have either cronjob function and schedule task (i asked host provider ,they said they donnot have it)
So have any scripts(php,javascript....) to do this work(running a file on server with specific time)?
Thanks so much.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#2: Mar 31 '08

re: Cron Job


In a word no. You see, php, javascript, html etc are all only "run" when they are called. So when a user goes there is one of two ways it can be called. The second way is if a server automatically runs it. This is usually done with cronjobs and is really what you need.

May I ask which provider you're with?

What does the file do that you want to run in a cronjob? Maybe there is a way around it?
Member
 
Join Date: Feb 2008
Posts: 50
#3: Mar 31 '08

re: Cron Job


Thanks TS!!! they are my local provider,i m sure you dont know them.
I want to run a script to import data from xml file to mysql.it will be run everyday at specific time.
are any solutions for it?
Thanks
dlite922's Avatar
Expert
 
Join Date: Dec 2007
Location: Moon, Dark Side
Posts: 1,095
#4: Mar 31 '08

re: Cron Job


Quote:

Originally Posted by th1982

Thanks TS!!! they are my local provider,i m sure you dont know them.
I want to run a script to import data from xml file to mysql.it will be run everyday at specific time.
are any solutions for it?
Thanks

yes there is.

from a computer that has internet access around the time you want to run it, and do a scheduled task/cron job that calls a PHP file that does exactly that.

Good luck.
TheServant's Avatar
Expert
 
Join Date: Feb 2008
Location: Australia
Posts: 913
#5: Mar 31 '08

re: Cron Job


I think that's what we're talking about? But yeah, if your provider doesn't offer it, you will need to schedule it on your own computer and so it has to be on. If it is only once a day, this isn't too big a task. A lot of mine (will) run every 10mins, so it's really impossible for me to use that option.

Actually, I have thought of another way. It's a little fiddley, but it should work. What you is you have a small bit of code at login (or a common page) that checks the time against when the last time your file was run. So you need to have another MySQL table which just stores the last time it was run.

When the user (anyone) goes to your site and logs in, a bit of code will run and check if the current time is over 24 hours from the last run time. If it is, it will execute that file and do what you want. If not, it will continue as normal.

I know it's probably been done before, but I've never heard of it, so for the next 5mins we will pretend that I am a genius ;)
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#6: Mar 31 '08

re: Cron Job


Quote:

Originally Posted by TheServant

I think that's what we're talking about? But yeah, if your provider doesn't offer it, you will need to schedule it on your own computer and so it has to be on. If it is only once a day, this isn't too big a task. A lot of mine (will) run every 10mins, so it's really impossible for me to use that option.

Actually, I have thought of another way. It's a little fiddley, but it should work. What you is you have a small bit of code at login (or a common page) that checks the time against when the last time your file was run. So you need to have another MySQL table which just stores the last time it was run.

When the user (anyone) goes to your site and logs in, a bit of code will run and check if the current time is over 24 hours from the last run time. If it is, it will execute that file and do what you want. If not, it will continue as normal.

I know it's probably been done before, but I've never heard of it, so for the next 5mins we will pretend that I am a genius ;)

What if noone visits the page for months?

OR EVEN YEARS?!

I don't believe it's too hard to, on your own pc, use windows schedule task manager.

Regards.
Member
 
Join Date: Feb 2008
Posts: 50
#7: Apr 1 '08

re: Cron Job


Thanks so much!!!
but when i use schedule task ,i can only see the applications on my computer.How can i set to run a php file on server ?sorry,i m first time using this task .
Thanks
best regards
Newbie
 
Join Date: Mar 2008
Posts: 14
#8: Apr 1 '08

re: Cron Job


Hi!
In your schedule you'll need to specify an application or a script that does the task of calling your remote script url.
You could for example call a web browser with the url as argument. A more elegant alternative would be to write a VB script to call the url. An example VB script can be as follows:
Expand|Select|Wrap|Line Numbers
  1. 'scriptfile.vbs
  2. Call LogEntry()
  3. Sub LogEntry()
  4.         On Error Resume Next
  5.         Dim objRequest
  6.         Dim URL
  7.         Set objRequest = CreateObject("Microsoft.XMLHTTP")
  8.         URL = "http://YOUR-URL"
  9.         objRequest.open "POST", URL , false
  10.         objRequest.Send
  11.         Set objRequest = Nothing
  12. End Sub
Hope this could be of help.
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,936
#9: Apr 2 '08

re: Cron Job


Quote:

Originally Posted by th1982

Thanks so much!!!
but when i use schedule task ,i can only see the applications on my computer.How can i set to run a php file on server ?sorry,i m first time using this task .
Thanks
best regards

Just open your task scheduler, then select your internet browser as the action (giving the url of your script as an extra argument).

Regards.
Reply