How do i load scripts with a specified times [duplicate] - php

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
How to execute PHP code periodically in an automatic way
I am trying to find a way in PHP to load specified script in a specified time, For example if the apache server can execute a specified script, Or mabye there is an option inside the php.ini so i can add files to load in a specified times.
For example:
I want to load the script example.php this file can be found inside the root directory at the location X/Y/example.php, What i want is that the Php engine/Apache Server will execute this script at 12:00, If anyone know a way doing so i will be very thankful, Thank you all and have a nice day.

Use cron
Cron is a daemon that executes scheduled commands. Cron is started
automatically from /etc/init.d on entering multi-user runlevels. Cron
searches its spool area (/var/spool/cron/crontabs) for crontab files
(which are named after accounts in /etc/passwd); crontabs found are
loaded into memory. Note that crontabs in this directory should not be
accessed directly - the crontab command should be used to access and
update them.
For more info:
croninfo.html
Wiki

cronjobs and GET is all you need

Related

automatic email without form submission in php [duplicate]

This question already has answers here:
How can I make my PHP script run at a certain time everyday? [duplicate]
(8 answers)
Closed 5 years ago.
I have to send emails automatically on weekend basis by checking database values without form submission or button using codeigniter.is there any idea. someone please help
PHP call with CRON
If what you want is run a php script (that send emails or do what ever you want) automatically, use CRON on your server (if you are on Linux of course) by editing crontab with this command :
crontab -e
Add this line in the end of the file and save it :
0 8 * * 0 /usr/bin/php /home/toto/test.php
This example execute the script test.php in toto home directory every sunday at 8 AM.
More info on how to use cron here : Execute PHP script in cron job
PHP call from MySQL Trigger
There is another way to call a PHP script automatically every sunday or when ever you want, by creating a Trigger on MySQL. Especially if you can't use CRON, on Windows for example (WAMPP). You will use the sys_eval commande in your Trigger procedure.
sys_eval("C:/xampp/php/php.exe -f "C:/xampp/htdocs/phpFile.php");
Here is a good example for this solution : https://stackoverflow.com/a/2763238/2282880
Note : On Windows Server, you could use scheduled tasks to ru the php.exe app too. But never tried.

How should i run a long php script on weekly basis [duplicate]

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)

Issues with running multiple cron jobs

I am working on a project where I need to run 12 different PHP files, every night. 11 of these files are pulling data, each from a different external site and reformatting it into an XML file, for my purposes. The 12th file, combines the 11 XML files into a master XML file.
I had originally had these combined into a single PHP file but, it was far too much and kept timing out. They work fine, separated as they are.
I'm on a GoDaddy shared hosting plan and started setting up cron jobs to run these files every night. However, GoDaddy limits you to 10 cron jobs total.
So, as an alternative, I placed a header redirect at the bottom of the first 10 files (obviously the last file doesn't need a redirect), to redirect to the next one and run it. This consolidates 11 cron jobs down to 1.
// On to the next
header('Location: http://www.domain.com/secondFile.php');
I did not realize, at the time, that header redirects only work in the browser, not in cron jobs. I'm getting a 302 Moved Temporarily message.
What other options do I have here? Are there redirects that will work in cron jobs?
Any info provided is appreciated.
Thanks to Barmar's help, I've got it working now. Posting the format here for anyone else having the same issue, on GoDaddy hosting.
generatexml.sh
#!/bin/sh
/web/cgi-bin/php5 /home/content/u/s/e/username/html/firstFile.php
/web/cgi-bin/php5 /home/content/u/s/e/username/html/secondFile.php
/web/cgi-bin/php5 /home/content/u/s/e/username/html/thirdFile.php
etc.
Run a single cron job containing a shell script to run each of the PHP scripts:
#!/bin/sh
php firstFile.php
php secondFile.php
...
run the script via your webserver and wget.

how do I run php code without users visiting the page? [duplicate]

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/

How can I make my PHP script run at a certain time everyday? [duplicate]

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.

Categories