2

As implied in the title, the Cron Job is supposed to execute a php file (update.php, to be specific). The php file then writes to a csv file stored in the same directory.

I have the time set to * * * * * so that it executes every minute. The command is written as follows: php -q /home//public_html/wallboard/update.php I don't believe this is causing any errors, though it also doesn't seem to write to the CSV file. When I visit update.php in a browser, however, it executes and writes to the CSV file immediately. I'm not experienced with Cron Jobs and I'm sure there's an issue, but I don't know what exactly that issue is. Let me know if you have suggestions/questions. Any help is appreciated!

Current Command:

* * * * * usr/bin/php -q /home/<user>/public_html/wallboard/update.php

update.php:

<?php

include('lib/HelpDeskView.php');
include('lib/WallboardDisplay.php');
include('helpdesk.csv');
$helpdesk = new HelpDeskView();
$text="\r\ntest,test,test";
file_put_contents( "helpdesk.csv" , $text, FILE_APPEND);
IIama
  • 23
  • 1
  • 4
  • try changing `php` to `/usr/bin/php` – WheatBeak Jul 26 '17 at 20:34
  • 1
    Your relevant code + full command of Linux, please paste here. – Muhammad Usman Jul 26 '17 at 20:35
  • Try setting update.php permissions to 755. – Konrad Jul 26 '17 at 20:49
  • 1 - You may need to include full directory names in the include statements as PHP may not think of the same starting directory when run in command-line mode like this as when it is run by the web server. 2 - My hosting company, using their own control panel, NOT cpanel, runs PHP cronjobs by using the full directory-path/name of the file instead of using /usr/bin/php with the filename and gets PHP to run correctly by putting `#!/usr/local/bin/php.cli` in the very first line of the file. 3 - My hosting company says to use permissions 775. – manassehkatz-Moving 2 Codidact Jul 26 '17 at 20:59

4 Answers4

5

Since your script resides in your public_html directory you can use wget for your Cron Job

wget -O - -q https://yoursite.com/wallboard/update.php

-O - output is written to the standard output in this case it will go to the email address you specify in CPanel

-q quiet mode

cmorrissey
  • 8,493
  • 2
  • 23
  • 27
3

IMHO the best way is to contact support and ask them about command line syntax.


This is how I'm doing it at my linux server using cPanel.

enter image description here

This runs script.php which is stored in public root. Course, replace <username> in command line with your username.

At another server I'm using same command line with /usr/bin/php instead of php at the beginning of line, but I'm aware that not all servers use same command line. Some require php-cli in command line instead of php, some don't "like" -f argument, etc. So try various combinations.

To find more suggestions check out this SO topic too: Run a PHP file in a cron job using CPanel

Important thing: When trying different commands wait at least a minute (this case) to see if it works because Cron doesn't fire your script immediately.

Wh1T3h4Ck5
  • 8,399
  • 9
  • 59
  • 79
0

Try to execute the same command in PHP CLI and check if it gives you any error, you might be missing some libraries or references required for CLI execution.

Azaz Khan
  • 637
  • 1
  • 8
  • 20
0

/usr/bin/php -d register_argc_argv=On /home/USERNAME/public_html/DOMAIN/artisan AMIR:HOME

Amir Hosseinzadeh
  • 7,360
  • 4
  • 18
  • 33