peppeocchi / php-cron-scheduler

PHP cron job scheduler
MIT License
808 stars 143 forks source link

Crontab doesn't run scheduler.php #55

Closed mcoiffier closed 6 years ago

mcoiffier commented 6 years ago

Hello, First of all thanks for PHP Cron Scheduler, I feel that it will simplify my life (but not yet ;)). However, I can not make the scheduler work, despite reading the readme carefully.

Here is my file scheduler.php <? php require_once __DIR __. '/ vendor / autoload.php'; use GO \ Scheduler;

$ scheduler = new Scheduler ();

$ scheduler-> call (function () {     echo "Hello";      return "world!"; }) -> output ( 'myfile.log');

$ Scheduler-> run (); ?>

And here's what the command crontab -l sends me back (after adding in my crontab): * * * * * / usr / bin / php /Applications/MAMP/htdocs/test/scheduler.php 1 >> / dev / null 2> & 1

myfile.log file is already creating and even after waiting for many minutes it remains desperately empty.

Note that it works when I do directly in terminal: /usr/bin/php /Applications/MAMP/htdocs/test/scheduler.php

What's wrong with my approach?

Thanks for your help !

mcoiffier commented 6 years ago

False alarm! In my file scheduler.php the output path was relative so I was writing in the wrong place.

output ('myfile.log')

I added the following line in my crontab * * * * * env > /tmp/result I found my file at the path written in the PWD value.

In case of people having problems with their crontab:

1) Try running your script directly from the command line to see if the errors comes from your script 2) The value of the php binary can be different from /usr/bin/php, take the result from: which php 3) Check execution permission for the file: chmod + x file 4) Ideally use absolute paths

peppeocchi commented 6 years ago

@mcoiffier thanks for sharing that!