I am working on a project where the wget and crontab are used to run a process in the background. I have a php file named "Hello.php" that I want to run this every 5 minutes. I have found that if I want to have a cron job run every 5 minutes, I should use the following crontab entries :
*/5 * * * root wget ..... # Other processes run as such
* * * * * root wget https://hello.com/cron/advertise
How can I link my "Hello.php" class with cron to run in every 5 minutes?
I am using symfony2.
use the console component
make it run your hello.php script
call the command in your crontab
bash /your/dir/app/console yourcommand
or even simpler run php your/dir/hello.php
Related
I have setup a cron job thusly:
*/15 * * * * root /usr/bin/php5.6 /var/www/example.com/cr.php
(Yes, root is owner for now - I'll fix that later)
I have also tried with -q after .../php5.6
but it doesn't seem to be working, even though syslog shows it executes every 15 minutes - for example:
Dec 20 17:45:01 e2e-53-27 CRON[2601]: (root) CMD (root /usr/bin/php5.6
-q /var/www/example.com/cr.php)
If I execute the part after the username 'root' at the bash prompt it does work.
This is apache2 running on Debian. I don't know if this makes any difference but the PHP file is using curl to call an external API that sends an SMS.
You should use this format in cron file to make it work:
*/15 * * * * /usr/bin/php5.6 /var/www/example.com/cr.php
And the best way is to put this in script and add as first line in the script command:
. /root/.bash_profile
to make the environment as it is in command line
I have a php file which I want to be executed every 15 minutes. I have the cron job set up already. I just want to know what command I would use?
My file is located in ~/app/example/myfile.php. So you can't access it through a URL. Otherwise I would have just used wget -q -O /dev/null "URL"
In your crontab it'd be
0,15,30,45 * * * * php /path/to/file.php
I want to add cron job based on record inserted time, After 12 hours, if once function run automatically remove the cron job based on php script is this possible?
actually i tried with below
$t=shell_exec('echo -e "`crontab -e` 30 9 * * * /path/to/script" | crontab -');
echo $t;
But nothing will work
Below the commands u can use on the cli to add a cronjob to the crontab. But like Gordon mentioned before it makes more sense to generaly add a cronjob which than (every 5 minutes, hour etc.) checks your jobqueue for tasks which have to be started.
#write out current crontab
crontab -l > mycron
#echo new cron into cron file
echo "00 09 * * 1-5 echo hello" >> mycron
#install new cron file
crontab mycron
rm mycron
I'm trying to a execute scheduled command every five minutes in background. I use this code
protected function schedule(Schedule $schedule)
{
$schedule->command('read:mail')->cron('*/1 * * * * *')->sendOutputTo(storage_path().'/logs/output.txt')->withoutOverlapping();
}
I suppose that this code is fine, when i use php artisan scheduler:run command works, but doesn't work every five minutes in background. ¿Any idea?
If you want to use the scheduler you need to add a Cron entry in your server, this line will call the Laravel scheduler every minute and do the tasks.
There is the line you need to add to your Crontab:
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
In case you are using Ubuntu to edit your crontab you can run crontab -e and add the line on the bottom.
You can read more on the official docs about Scheduling.
If you are using Windows you can follow this Stackoverflow question to add a task to the Windows task scheduler.
I'm having a PHP script which I want to run every 2 minutes using a Cron job in Ubuntu. I'm getting the following error:
bash: */2: No such file or directory
I've completed all steps below to set up a Cron job.
Please help me to resolve the error, I don't understand what I'm doing wrong.
1) Write this command in my terminal: where is php
Output:
php: /usr/bin/php /usr/bin/X11/php /usr/share/php /opt/lampp/bin/php /usr/share/man/man1/php.1.gz
2) Run a PHP script every 2 minutes:
*/2 * * * * /usr/bin/php /opt/lampp/htdocs/kyrill/filetest.php
Output:
bash: */2: No such file or directory
Seems like you are executing the crontab directive.
Execute
crontab -e
to edit your cron jobs. Then add this line at end of the file
*/2 * * * * /usr/bin/php /opt/lampp/htdocs/kyrill/filetest.php
try
0/2 * * * * curl http://[your_id:port]/kyrill/filetest.php