command in cron to run php every certain mins - php

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

Related

How to create cron job using php script?

I want to run my file's code every minute. Please help me. I never used cron job so I am not able to do it.
crontab -e
*/1 * * * * "job every minute"

Cronjob and PHP working together?

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
- ...

Run a scheduled SQL Query

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

Add FuelPHP task to cron job using CronTab

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.

Setting up the crontab on amazon ec2 cloud (Linux server)

I need to run a php file on every 2 hours, so i am using this command
* */2 * * * /usr/bin/php /var/www/html/sports/webservices/rss-insert.php
i am also using this
* */2 * * * php /var/www/html/sports/webservices/rss-insert.php
But both are not working. can anyone help me.
Thanks
The crontab you have made will run every minute of every second hour rather than every two hours.
In order to get it to run every two hours you need something like this:
5 */2 * * * /usr/bin/php /var/www/html/sports/webservices/rss-insert.php
which will run it 5 minutes after every second hour e.g 2:05, 4:05...
This is assuming your script is able to run. Try running the command portion from the cron by hand at the command line and make sure it does what you want.
This works for me definitely work for you.
0 0-23/2 * * * php /var/www/html/sports/webservices/rss-insert.php

Categories