PDA

View Full Version : php script called from Cron job


ManuTOO
01-07-2005, 03:58 AM
Hello,

I'm using www.powweb.com's hosting.
I set up a PHP script that process all the mails in my Inbox, and depending of the subject, it flags them and call another PHP script presents on my web that will generate an answer, and send a mail.

1st, I tried the processing script from the web, and called the 2nd php script like this :
fopen("http://localhost.mydomain.com/mail.php?name=$Name", "r");
It worked fine.
Then, I put the script in the etc dir, and called it as cron job. The script just runs fine coz I see it still flags the found emails, but the call to the external script by fopen(...) just produces nothing !

I tried with other URLs :
- http://www.mydomain.com/mail.php
- /www/u/uuuu/htdocs/ (u/uuuu is my user name)
- http://localhost/htdocs
still without anymore success.
I don't have any error shown in the cron log...

Anyone has an idea about what could go wrong ?

Thanks,

Rod Hyde
01-07-2005, 04:10 AM
Anyone has an idea about what could go wrong ?
I can't speak for PHP, but a frequent reason for failures of cron jobs (or scripts called indirectly by cron jobs) is one of environment. When cron starts, it usually has a very limited environment, so you might want to configure your environment explicity at the start of your script.

--- Rod

ManuTOO
01-07-2005, 12:45 PM
Hello,

thanks for ur answer, it seems really interesting...
Unfortunately, looking with Google for "configure cron environment", I only found this parameters :
- SHELL=/bin/bash
- PATH=/sbin:/bin:/usr/sbin:/usr/bin
- MAILTO=root
- HOME=/
and it seems none is relative to the thing I need.

Do u know any website I could find these infos ?

Else, I guess I'd use a command line call, but I'd have to convert my argument passing, and I'm afraid to find new annoying things... :-S

Rod Hyde
01-07-2005, 03:30 PM
Well, you could always invoke a wrapper script that sets up the environment before running what you were originally trying to run. I have no idea which shell you are using, so I've given an example using Korn shell.

eg,
#!/usr/bin/ksh

# set up your environment
export PATH=your_path_additions_go_here:$PATH
export ... any other environment variables that you need

# now run your program (the $* is whatever you passed in to this script)
your_program $*
--- Rod

Kai Backman
01-08-2005, 08:24 AM
I installed cURL and used it to grok the URL. Easier and more reliable than playing around with fopen which is IMHO slightly hackish (cool in itself but will not neccessarily get you there). :)

luggage
01-08-2005, 09:04 AM
I installed cURL and used it to grok the URL.

I don't understand a word of that! :eek: Glad I haven't got to do any of this stuff yet.

ManuTOO
01-08-2005, 02:59 PM
Hello,

After saw I couldn't use argument passing without setting a local PHP.ini (and get probably new troubles), I went to the easiest & simplest solution : have everything in the same script, using the "include" command (same as in C/C++), and wrapping my mailer script in a function called by my inbox processing script.

Pffff.... It's really not easy to find precise infos & conduct test on this stuff...