Add FuelPHP task to cron job using CronTab - php

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.

Related

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

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

How to write cron job in AWS EC2 server

I've created a cron job in AWS EC2 but it is not working.
I followed below steps to create cron tab:
Step 1: I logged in to AWS EC2 Instace
step 2: crontab -e
Step 3: Insert mode
Step 4: I entered * * * * * php/var/www/html/welcome.php (To run every min.)
Step 5: :wq
Cron tab is created but not running.
Please can you any one help me if is there any PHP script means please provide me. Do I need to give spaces between every star?
First of all, you need to put an space between php and /var:
From
* * * * * php/var/www/html/welcome.php
to
* * * * * php /var/www/html/welcome.php
^
Then, you'd better use /bin/php instead of just php. To determine where the php executable is located, type which php in your console, it will give you the file path. So it will become something like this:
* * * * * /bin/php /var/www/html/welcome.php
^^^^^^^^
More things:
check if crontab is saved properly? Type crontab -l. Your new crontab line should be there.
is the script exactly in this dir? Try ls -l /var/www/html/welcome.php.
is the script executing if you do from console? Try /bin/php var/www/html/welcome.php to see if it is a script or crontab problem.
does the script have executing mode? Try chmod 755 /var/www/html/welcome.php
Keep us updated so we can find what can be causing the error.
May be a too late but anyways if you intend to run the script every minute the command should probably be
* * * * * php /var/www/html/welcome.php
Running cron on EC2 is not any different from running on any *nix server - as far as I know.
I would check of the system messages for any errors. You can also redirect stderr/stdout to a file as in
* * * * * <your script> >> /var/tmp/out.log 2>&1
and check for any issues for starters.

command in cron to run php every certain mins

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

Setting up cron job to execute a PHP Script

I need to setup a cron job that'll execute a PHP script (used to send iPhone notification to users) every minute. I've tried several code snippets but none of them seem to work. Here's what I've tried:
crontab -e
then..in the editor, i typed
* * * * * php /Users/MYUSERNAME/Desktop/SimplePush/simplepush.php
but it doesn't work. I'm running on Mac OS X Lion and will be deploying the service on Linux service but i think the crontab ability shouldn't quite be affected by the OS as both are based on unix core. So, anyway, I need this cronjob to fire simplepush.php every minute to send notifications. How do I do it?
Have you tried running php /Users/MYUSERNAME/Desktop/SimplePush/simplepush.php in the terminal to check if it's working?
use this code :
* * * * * wget -q /Users/MYUSERNAME/Desktop/SimplePush/simplepush.php
or
* * * * * wget -o /Users/MYUSERNAME/Desktop/SimplePush/simplepush.php
I know this is an old question but this works for me in OSX Yosemite
*/1 * * * * php -q /Users/path/to/php-file.php

Categories