Forum Moderators: phranque

Message Too Old, No Replies

cronjob with simplexml load string()

         

glimbeek

9:36 am on Apr 12, 2010 (gmt 0)

10+ Year Member



Hi,

Not really sure this is supposed to go in here or in the PHP section of the forum... anyway, on to my problem.

I made a script that uses the PHP function to read a RSS feed and create a xml from that RSS feed.

If I browse to my script with my browser e.g. http://www.example.com/myscript.php, the script loads. If I then check my FTP, the .xml file is created. If I then empty the file or delete it and I browse to my script again, the .xml file gets overwritten/recreated.
So far so good.

To automate this process, I created a cronjob to run every 5 minutes. My cronjob uses the following command:

/usr/local/bin/php /home/example/www/myscript.php

The cronjob has been running for a while but .xml file doesn't get updated. I checked the log files for the cronjob but there are no errors in it. In my control panel I have the option to run the cronjob straight away, so I do and I get the following result:

Output from command /usr/local/bin/php /home/example/www/myscript.php ..

X-Powered-By: PHP/4.4.8_pre20070816-pl1-gentoo
Content-type: text/html

<br />
<b>Fatal error</b>: Call to undefined function: simplexml_load_string() in <b>/home/example/www/myscript.php</b> on line <b>46</b><br />

Why does the cronjob "fail" when it loads my script but when I browse to my script everything works fine?

I'm using:
PHPVersion 5.2.5-pl1-gentoo

SimpleXML
Simplexmlsupportenabled
Revision $Revision: 1.151.2.22.2.35 $
Schema support enabled


curl
cURLsupport enabled
cURLInformation libcurl/7.16.4 OpenSSL/0.9.8g zlib/1.2.3


xml
XMLSupportactive
XMLNamespace Support active
libxml2 Version 2.6.30

Thanks in advance for any support.

jdMorgan

1:43 pm on Apr 12, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Possibly because the script (and all libraries that it calls) are configured to execute under the "Web access" owner, and cron runs under your (or the server's) account.

Unfortunately, that's all I know -- You might want to see if there's an easy way to display the owners of all running processes, and compare your cron process and script process owners.

"chown" is the *nix command to change ownership.

Jim

glimbeek

2:11 pm on Apr 12, 2010 (gmt 0)

10+ Year Member



Hi Jim,

Thanks for the reply!

If I run the cronjob with root or with my "web access owner" results in the same error.

I could try using the user "Apache" but I doubt that's very safe...

glimbeek

11:30 am on Apr 13, 2010 (gmt 0)

10+ Year Member



From the looks of it seems that my "webserver" uses PHP5 and the cronjob php4... Oddest thing.

glimbeek

10:39 am on Apr 20, 2010 (gmt 0)

10+ Year Member



Solved it.

Pointing towards php5 instead of php4 did the trick e.g. /usr/local/bin/php5 instead of /usr/local/bin/php.

jdMorgan

1:46 pm on Apr 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Oddest thing.

Agreed! We get a lot of that here...

Thanks for posting your solution!

Jim