This question already has answers here:
How to create cron job using PHP?
(11 answers)
Closed 5 years ago.
I have a long PHP script (for scraping), It takes around 2 hours to execute, I want to run this on weekly basis, I have cron job option in Cpanel and i know how to use it, But i think it is not useful for that long scripts
I read some other answers about long PHP script, They say long PHP script should be executed via shell. I read this blog http://symcbean.blogspot.com/2010/02/php-and-long-running-processes.html But i couldn't understand anything,
I have never worked with shell, But i can spend time to learn it, But would it be possible to run the script via shell and also on weekly basis at same time automatically
When you run a cron job it basically runs a shell command of your choosing.
That shell command can be php <your_script_name_here>.php
I think anyway that cron job is the way to go (scheduled task on windows machine).
If you have a script fro scrapping I recommend you to use HHVM instead of php-fpm you gonna gain lots of performance.
And in second part you gonna need may be a worker or a job queue system to run your script via a cronjob.
If you insert data in your data-base don't insert row by row but create an array with all data and then insert all in one time. (there is lot of thing you can do to have best performance)
Related
This question already has answers here:
PHP: running scheduled jobs (cron jobs)
(13 answers)
Closed 9 years ago.
Basically what I need to do is to update a database every X days/hours/minutes/seconds (to be set). How can I let a PHP page execute regularly?
Use a CRON job.
If you are using a hosting service with cpanel there is an option to set and it can be quite straightforward.
Otherwise there are plenty of CRON tutorials on the interwebs.
Be sure that the permissions on your script are set correctly for it to be executed.
This feature is not provided by php, but by another program depending on your operating system (crontab in unix, scheduled tasks in windows).
your choices are cron (as everyone is mentioned) in unix, task scheduler in windows,
or a header in your php to check a file to see if whatever you need to happen has been processed in the last X minutes / hours / days
but the php-option is a terrible idea if cron/task scheduler is at all possible.
You can have for instance an HTML page reloaded every 15 seconds like this:
<META HTTP-EQUIV="refresh" CONTENT="15">
but is certainly wise to do this via cron or corresponding system tools to schedule repeated a programs.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to run a php script in cron
I need to run a php script at the scheduled time daily to update some fields in database and to send automated email. How I can do this?
Is it possible to write some service in XAMP server to run the script daily at scheduled time? I have no idea how to update database and send email automatically at the scheduled time. Can any one share some ideas or concepts?
I am using PHP and MySQL running in Linux Server.
Is it possible to write some service in XAMP server to run the script daily at scheduled time?
Create a Cron Job.
Look into CRON Jobs: http://en.wikipedia.org/wiki/Cron They will allow you to schedule multiple scripts to run automatically, without your intervention on a determined schedule.
you should use cron job, it will run your script automatically
http://www.thegeekstuff.com/2011/07/php-cron-job/
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Best way to periodically execute a PHP script?
I need to run a php script which continuously collects information from one site, and as soon as that information is collected I need the server to store the information on the database and then update other sites and to continuously repeat the process. The only problem is that I need these php scripts to run without the user visiting the page or even the site for that matter.
Not only this I need the scripts to be running 24/7 or at least run when one site has changed, enabling it to update the others almost instantly. Can anyone suggest what I can do?
You could have your PHP script run as a cron job.
(Of course, you'll need to be able to set up cron jobs on your server)
You are looking for Cron Jobs: http://en.wikipedia.org/wiki/Cron
Many hosting providers have an interface that lets you set up jobs. If your provider uses CPanel, then see this page: https://documentation.cpanel.net/display/68Docs/Cron+Jobs
If on Windows, then use Scheduled Tasks.
You have to create daemon using PHP.
Have a look at this http://devlog.info/2010/03/07/creating-daemons-in-php/
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP Curl script to pull data from remote server every 10 minutes
My friend's website has XML generator for news feeds. I'm reading data from there and use it on my website (I have permission to do that). But... I have a script for that job under my admin panel so I have to call it manually and wait until processing is done (can't close my browser). It works great but problem is that I need to update my database every 30 minutes (or every hour) and I can't stay in front of my computer doing that 24 hours daily.
I'm now wondering, is there something that I can do to make this process automatized on server-side? In short, I want to run some kind of scheduler on my server that runs my script every (lets say) 30 minutes and do that job without my physical presence in front of computer.
I have not experience at all about this and actually don't know where to look to find solution for this problem. Don't know is that even possible?
So what I need here as answer is some suggestions or links or whatever helps in order to find solution for my problem. It's not urgent and I have a lot of time to learn. Just tell me where to start searching.
Sorry if this is duplicate question, but I couldn't search for anything because I didn't know what search terms to use and have not idea yet what I have to look for.
I really appreciate any suggestion.
What you are looking for is cron (quoting) :
Cron is a time-based job scheduler in Unix-like computer operating
systems.Cron enables users to schedule jobs (commands or shell
scripts) to run periodically at certain times or dates. It is
commonly used to automate system maintenance or administration...
You could use curl in order to do the job you are doing right now in your browser, and after that, put that command in cron
This question already has answers here:
PHP: running scheduled jobs (cron jobs)
(13 answers)
Closed 5 years ago.
I have a PHP script that checks my database's code for validity. How can I have this run everyday at a certain time so then I can just have it run on autopilot.
What you want is called a cron job and is already covered here:
PHP: running scheduled jobs (cron jobs)
If you are using cPanel on your host, you can go to Advanced --> cron jobs.
Then inside there you can set a cron job command like this:
wget http://yoursite.com/yourfile.php
which http://yoursite.com/yourfile.php should point to your desired function.
You can also set repetition time interval over there.
This way yourfile.php is called in specified intervals.
CronJobs feature are often disabled on most free or cheap Linux hosting. If you could use cron you could use that.
Alternatives:
Use services like : http://www.setcronjob.com/ (many exist, just search on google) , to schedule your task for free(1x per hour).
If you need a little bit more juice you should look into google app engine cron. In the cron you just do a simple asynchronous request to call your page.
There's a cli interpreter called php. Run your script through that as a cron job.
If you are a linux/unix user, i recommend you use CRON .
May it will helps you.
You can schedule a task in Windows - control panel->administrative tools is where you find task scheduler.
run a php automatically after every hour
Thanks
If you have your own server you can run a cronjob(unix/linux) or a scheduled task(windows).
If your app/site is hosted on a shared host that does not offer cronjobs you an use a sevice like
http://www.onlinecronjobs.com/
I have not tested this one but If you google a bit(fee conjobs) you will find plenty of those.
They will call a certain a url accoding to a fixed schedule. Most of those sevices have a fixed set of ip addeses so you can pevent the scipt from being called by anyone else.
You can easily use your database to save the last execution of the script.
Each execution of a certain page you run a script that does the following :
Check if more than 8 hours (example)
Checks in the database if the script has already been executed
If executed: does nothing.
If not executed: starts and updates the date last execution in database.