Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

Cannot run PHP in Linux cron job

Discussion of Ken True's web site templates

Moderator: saratogaWX

Post Reply
User avatar
N0BGS
Posts: 205
Joined: Sat 10 Nov 2012 2:26 am
Weather Station: Davis Vantage Pro 2
Operating System: Win10vm,VMWare ESXi 7.0
Location: Hermon, Maine USA
Contact:

Cannot run PHP in Linux cron job

Post by N0BGS »

Hi all:

I've spent the last 3 hours trying get this cron job to run on my own Fedora 17 box with Apache, and PhP 5.4.12:

5 * * * * /usr/bin/php /var/www/html/nws-alerts.p

Below is the error output:

PHP Warning: fopen(./cache/nws-alertsMainData.php): failed to open stream: No such file or directory in /var/www/html/nws-alerts.php on line 264
PHP Warning: fopen(./cache/nws-alertsBoxData.php): failed to open stream: No such file or directory in /var/www/html/nws-alerts.php on line 426
PHP Warning: fopen(./cache/nws-alertsIconData.php): failed to open stream: No such file or directory in /var/www/html/nws-alerts.php on line 515
<!-- nws-alerts.php - 1.14 - 05-Aug-2012 - NWS Public Alerts -->
<!-- Cron job enabled -->

<!-- cURL error: Connection time-out -->
<!-- http://alerts.weather.gov/cap/wwaatmget.php?x=MEZ015 -->
<!-- First attempt in getting preliminary URL failed -->
<!-- Second attempt successful -->
<!-- http://alerts.weather.gov/cap/wwaatmget.php?x=MEZ015 -->

<!-- Preliminary codes checked: 2 -->
<!-- Preliminary data cull: 20.4198 seconds -->
<!-- Average cull per code: 10.2099 seconds -->
<!-- Primary alerts downloaded: 0 -->
<!-- Primary data cull: 0.0000 seconds -->
<!-- unable to open cache file -->
<!-- unable to open cache file -->
<!-- unable to open big icon cache file -->
<!-- Total script process time: 20.4236 seconds -->
PHP Warning: fopen(./cache/nws-notes.txt): failed to open stream: No such file or directory in /var/www/html/nws-alerts.php on line 932
PHP Warning: fputs() expects parameter 1 to be resource, boolean given in /var/www/html/nws-alerts.php on line 933
PHP Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/html/nws-alerts.php on line 934

...of course, despite the error messages, all the files the scripts are looking for DO actually exist.

I'm a PHP moron so I suspect I am missing something simple--probably a permissions issue somewhere in the path. If I run that same command manually, it runs fine. I have checked and rechecked the perms on the html root folder, the files, etc all to no avail. Nothing seems to work regardless of which user runs the cron job--including root.

Probably for this same reason, my new Saratoga-based site is very slow. http://cheesewhiz.dyndns.org

Educated and even wild guesses welcome!

Thanks,

--Kurt
Blitzortung Station 1809
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Cannot run PHP in Linux cron job

Post by saratogaWX »

Likely, the only thing missing is doing a 'cd /your/home/directory' The cron command uses cron's working directory, not necessarily your document root directory for it's default directory, so a ./cache/ directory name is likely not available (or writable).

Instead of running a PHP script directly, run a shell script (I call 'cronscript.txt') instead which contains

Code: Select all

#!/bin/bash
cd /var/www/html
/usr/bin/php -q nws-alerts.php
then have the cron command be

5 * * * * /bin/bash /var/www/html/cronscript.txt >/dev/null &2>1

Best regards,
Ken
User avatar
N0BGS
Posts: 205
Joined: Sat 10 Nov 2012 2:26 am
Weather Station: Davis Vantage Pro 2
Operating System: Win10vm,VMWare ESXi 7.0
Location: Hermon, Maine USA
Contact:

Re: Cannot run PHP in Linux cron job

Post by N0BGS »

Why didn't I think of that?? :idea:

Works perfectly. I removed the dev/null redirect temporarily to see the output and there are no errors.
Came back to the forum when I noticed that a west coast IP address was showing up in my httpd access.log. :)
Thanks for checking the other stuff, too, Ken.

The scripts are a very nice piece of work. Thanks for making them available to us, and thanks for a very fast reply.

...now to make the rest of it work properly!

Take care,

--Kurt
Blitzortung Station 1809
User avatar
saratogaWX
Posts: 1238
Joined: Wed 06 May 2009 5:02 am
Weather Station: Davis Vantage Pro Plus
Operating System: Windows 10 Professional
Location: Saratoga, CA, USA
Contact:

Re: Cannot run PHP in Linux cron job

Post by saratogaWX »

N0BGS wrote:Why didn't I think of that?? :idea:

Works perfectly. I removed the dev/null redirect temporarily to see the output and there are no errors.
Came back to the forum when I noticed that a west coast IP address was showing up in my httpd access.log. :)
Thanks for checking the other stuff, too, Ken.

The scripts are a very nice piece of work. Thanks for making them available to us, and thanks for a very fast reply.

...now to make the rest of it work properly!

Take care,

--Kurt
You are very welcome, Kurt -- yes, that was me checking out your site.

Thanks for the kind words about the scripts -- it is truly a hobby (weather/websites) that keeps your interest up :)

Best regards,
Ken
Post Reply