-1

I have a php script that grabs links from another website. I am storing these links in my local system database using wamp server but my internet speed is so slow. I have to refresh the php script in browser after every 10 records.

So, can I run this PHP script on my webhosting server continuously for 24 hours and store all the links same as my local system. If it is possible then please help me.

8
  • Are you doing this from your local computer? What operating system are you running? Commented Jun 25, 2012 at 17:32
  • not what OS are YOU running but what OS is on the server that will be running the cron. Commented Jun 25, 2012 at 17:33
  • Yeah, as per @Bot ^ - is this a Linux server? (I'd missed that you want to transfer this to a remote host - have not re-paragraphed the question to make it easier to read!). Commented Jun 25, 2012 at 17:34
  • 1
    Also note that a cron script will execute based on time, not number of records. Commented Jun 25, 2012 at 17:35
  • 1
    Duplicate stackoverflow.com/questions/692208/… stackoverflow.com/questions/1972690/… Commented Jun 25, 2012 at 17:37

1 Answer 1

3

Type in crontab -e in the/a terminal or through PuTTy on your server, enter something to the like of the code below, where m is minutes, h is hours, dom is days of the month, etc etc etc

# m   h       dom     mon     dow     command
*/5   *       *       *       *       php -f /directory/to/file/filename.php

This will run it every five minutes.

If you want to run it continuously (which it doesn't really do), it needs to be run piece wise, something like this would work, which would run it from 9.30-17.30 every day.

30-59/5 9 * * * script.sh
*/5 10-16 * * * script.sh
0-30/5 17 * * * script.sh

Here are the basics of cron, I suggest you read them.

Cron and Crontab

Sign up to request clarification or add additional context in comments.

6 Comments

but i want to run a script for 24 hours continously from any time. for example I want to start a script at 09:00 AM and want to run it for 24 hours Then how to do this
How long is the interval you want it to run? 5 minutes? 10? And I don't understand what you mean by run it for 24 hours? start at 9, and run until midnight?
actually this script stores the crawled links in the database and i want to store all links in one time only not by running the script daily. and i sure that all the links will store in 24 hours.So thats why i was asking.
So why not just run it every 5 minutes all day like the example above
Nice answer, +1. OP: yes, PHP background tasks are best running for a short while, rather than continuously. This is because PHP is prone to memory leaks; also, if it crashes, it will pick up where it left off on the next cron interval, rather than needing another system (or an admin) to restart it.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.