I have an SQL query that I want to run multiple times a day.
I want it to be run automatically.
Many are saying I should use Cron Job using the following code:
*/4 * * * * wget --spider file.php
It's actually exactly what I want but I really don't know where to run it in my php code.
If you use Windows : launch the Task Scheduler with this command : taskschd.msc.
It is a GUI, so I let you manage it, it is not so complicated.
If you use Linux/Unix : you have to use a cron job.
In a shell :
crontab -e
It launches vim editor, so inside it write :
*/4 * * * * php /directory/to/your/file.php
Or
*/4 * * * * wget http://your_server/file.php
For more information about crontab, read the links in the comments of your question or google it. ;)
This is what I need:
CREATE EVENT event_name
ON SCHEDULE [EVERY interval | AT timestamp]
DO event_content
For those who don't know | means OR
Thank you for the answers guys!
link: MySQL Manual
Related
I would like to put in place some cronjobs for my website.
My actual cronjob is:
4 * * * * /usr/bin/php /var/www/domain/backup.php
But it doesn't work.
Mannually the cron job is working.
With a service like https://www.easycron.com it's working too.
In Terminal, when I make crontab -e, I see my cronjob but it does not seem to run.
From where I can start my search to understand ?
Thanks.
In my server, when setting up a php file to run, I only have to put:
4 * * * * php /var/www/domain/backup.php. They run flawlessly. Works the same for my shell scripts as well with just bash /directory/thisScript.sh
I added this as an answer because my reputation score won't let me add comments yet.
I'm Working on a php app where I need to have a number count in a sql data base reset at the first of the month and at 12am everyday via PHP and MYSQL.
I have googled but found nothing. As far as I know PHP needs to be accessed by a client to be manipulated.
What is the best method of having the server do this on its own?
You can use crontab
* 0 * * * /path/to/my/script
You can use cronjobs. On windows 'scheduled tasks', on linux crontab. For linux:
crontab -e
A line have to look like this to be called every day 0 am:
* 0 * * * /bin/php -q /script/path
Or, to call the file via web but do not get the content:
* 0 * * * wget --spider "http://url.com/cron.php"
If you do not have a dedicated server, check your webspace control panel for this or ask your webhoster.
I wrote a PHP script that push a CSV file into a database. I want to do this automatically every minute. I know there is a way via cron on Linux but I don't know anything about bash and think cron can't give my PHP file a callback, so I can show a progress bar for the user to see the timer interval. What do I do?
You can enter your jobs using crontab -e. If your default editor is vi, I recommend to change it nano using export EDITOR=nano because it is easy to use for starters.
Every line of the crontab file represents a job. The first 5 tokens are : minute, hour, day of month, month, day of week respectively, the last one is command so in your case first 5 tokens will be * * * * * that means run this job every minutes when the second is '00'.
You can call your php files directly using this command : php /var/www/cron.php & or using a browser wget -O /dev/null http://example.com/cron.php If you use first one you cannot use some $_SERVER variables but if you use second one, it is like a real browser.
In your case you can use like this :
* * * * * wget -O /dev/null http://example.com/cron.php
to add a cron and make it run every minute, type crontab -e and add the following line
* * * * * command you need executing
example:
* * * * * ls -l /home/ > /usr/local/users.txt
* * * * * df -h > /tmp/filesystem_usage.txt
* * * * * service httpd restart
Look at this for a starter: http://kvz.io/blog/2007/07/29/schedule-tasks-on-linux-using-crontab/
Also remember that cronjobs don't support all $_SERVER vars like 'DOCUMENT_ROOT' and 'HTTP_HOST', so try to avoid them, or use a workaround.
Some 'callback' possibilities:
- Let your script trigger another script
- Redirect the output of your cron to an another bash script
- ...
I am trying to add a FuelPHP Task as Cron job using CronTab.
I added the command as
* * * * * /usr/bin/php /var/www/project1/oil r welcomeTask
While doing this when i see the cron log in /var/log/cron, it show the cron job is called, but nothing happens as per the code.
But when I execute same code
/usr/bin/php /var/www/project1/oil r welcomeTask
in terminal it get executed properly and gives correct result.
Can anyone suggest me the correct way to execute the FuelPHP Task using CronTab.
Thank you in advance. :)
Finally I solved the problem by doing
* * * * * cd /var/www/project1/; /usr/bin/php oil r welcomeTask
Thinking on Stephane comment, for a test environment it may work better something like:
* * * * * cd /var/www/project1/;FUEL_ENV=test /usr/bin/php oil r welcomeTask
Just for the record.
this might be a repeat.
i would like to run my index.php every certain mins. My server has option run cron command/ cron jobs. Someone please tell me what could should I use to schedule.
Thanks in advance.
First of all, why?
Second, crontab -e will allow you to edit your crontab. Then it's just as easy as
? * * * * php /path/to/index.php
You could use this command
Minutes Hours Day Month WeekDay
45 * * * * php /path/to/index.php *
Here is an article about a php cron manager
First, here is how cron works:
http://en.wikipedia.org/wiki/Cron
Then, the comand should look like this:
* * * * * cd /directory/of/the/script/ && php scriptname.php >> /directory/of/the/logfile.log