1

I have a simple script in my server and I need a cron job to make it run every minute. I am using cPanel to set it. What should I enter in the cron job "command" field? I am newbie with cron job commands, I have tried many different options:

/home/enkaizen/public_html/soporte/wp-content/scripts/index.php

/usr/local/bin/php /home/enkaizene/public_html/soporte/wp-content/scripts/index.php

/usr/local/bin/php -q /home/enkaizene/public_html/soporte/wp-content/scripts/index.php

/usr/bin/php /home/enkaizene/public_html/soporte/wp-content/scripts/index.php

/usr/bin/php -q /home/enkaizene/public_html/soporte/wp-content/scripts/index.php

But none seem to be working. I know my script is correct because when I run it manually it does what it is suppose to do.

For in case it helps, my host is https://www.frenzysolutions.com

Any ideas what can I be doing wrong?

Federico J.
  • 15,388
  • 6
  • 32
  • 51
karlosuccess
  • 843
  • 1
  • 9
  • 25

2 Answers2

2

To run php from cron try the f flag

php -f /home/enkaizen/public_html/soporte/wp-content/scripts/index.php

It is best practice to use the full path to the executable when using cron. Unfortunately this is distribution/os dependent but it is probably either /usr/bin/php or /usr/local/bin/php

ike
  • 38
  • 6
  • I tried that one "php -f /home/..." but it is not working. Other programmers have used: `/usr/local/bin/php -q /home/enkaizen/public_html/app/Console/cake.php revenue -app /home/enkaizen/public_html/app` also `/usr/local/bin/php -q /home/enkaizen/public_html/app/Console/cake.php revenuemail -app /home/enkaizen/public_html/app ` It tried to make mine similar to theirs but no luck. Please help – karlosuccess Jul 08 '15 at 14:57
  • Actually it works with your solution! . what happens is that I am using require_once scripts. When I take those off, it works, otherwise it does not. But I need those require_once files. Any idea how I can fix this? Thank you – karlosuccess Jul 08 '15 at 16:21
  • Are the require_once statements absolute paths like: ` ` or dynamic like ` ` ? – ike Jul 08 '15 at 16:58
  • They are absolute. I am "requiring_once" 2 files in a sub-directory and 1 files in a directory 2 levels down "/../..". – karlosuccess Jul 08 '15 at 17:14
  • http://php.net/manual/en/function.require-once.php indicates you may have better luck if you switch them to dynamic. – ike Jul 08 '15 at 17:34
  • Also http://stackoverflow.com/questions/31050192/running-a-php-file-from-crontab-that-includes-require-once – ike Jul 08 '15 at 17:37
  • The file I want to run with the cron job is `public_html/soporte/wp-content/scripts/index.php`, how can I include this file `public_html/soporte/wp-header.php`? .... `require_once (__FILE__ .'/../../wp-blog-header.php');` is not doing it. Please advise – karlosuccess Jul 08 '15 at 18:00
  • Try `require_once(__DIR__ . '/../../wp-blog-header.php');` – ike Jul 08 '15 at 18:04
  • No luck. I know the cron is hitting because if I remove the require_once and place a little function to write a log, it does it. I don't know what else to try... any other thought you might have? – karlosuccess Jul 08 '15 at 18:16
  • I just found out that the problem is when I require_once a wordpress file "wp-header.php", not when I require_once any other non wordpress file. Any idea why this might be happening? – karlosuccess Jul 08 '15 at 18:23
  • Probably, I have no more ideas. – ike Jul 08 '15 at 18:26
  • Thanks for your help! – karlosuccess Jul 08 '15 at 18:27
0

Are you getting any error with "php -q" command ?

Also you can use curl command instead of php -q to execute your scripts through command line.

24x7servermanagement
  • 2,520
  • 1
  • 13
  • 11