PEAR Mail Won't Work in Crontab'd PHP Script

I have a PHP script that works perfectly when requested from the server; however, when I command it to be ran via Crontab like so:
lynx -dump http://www.emarketbuilders.com/admin/send_campaign_cron.php

I get the following error sent to me via email:
                                   Not Found

   The requested document was not found on this server.
     _________________________________________________________________


    Web Server at emarketbuilders.com
LVL 14
EMB01Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
woolmilkporcConnect With a Mentor Commented:
While in the environment where the script works fine, issue 'printenv' and examine the settings found.
 Some important values? Assume that they are not there when the script is run by cron.
 
 It could help to let the script be run out of root's crontab, and prepending a 'su - [user]' so that the line reads

su - [user] -c "lynx -dump http://www.emarketbuilders.com/admin/send_campaign_cron.php"

where [user] is the one who normally runs the script (don't type the brackets [  ] )
 
 Sorry that I can't be more specific. I just don't know your environment, nor do I know what your script actually does.
0
 
woolmilkporcCommented:
Hi,
remeber that there is no PATH when running from crontab (besides /bin and /usr/bin).
You need to provide full paths not only in the crontab itself but also in the script.

wmp

0
 
EMB01Author Commented:
How should my Cron command work, then? My script currently does use the full path.
0
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

 
woolmilkporcCommented:
So check additional environment settings (variables)
Problems with cron are in almost every case related to some environmentals being uninitialized.
0
 
EMB01Author Commented:
I'm sorry I'm not very experienced with Crontab. Could you be more specific as to what variables you would like me to check and/ or how to check them? Thank you.
0
 
EMB01Author Commented:
Okay, it's working, now! I had a wrong file name and include path for PEAR; so when I fixed those and used Lynx it worked. One question: Is there any benefit to using Lynx or should I use something better (what's the fastest, best way to run the script)?
0
 
woolmilkporcCommented:
The only thing that comes to my mind right now is WebCon (w3c) -

http://www.w3.org/ComLine/

Don't know if it can do what you want it to, nor if it's faster/better than lynx.

HTH anyway,

wmp

0
 
EMB01Author Commented:
Would it be faster to just run it from the command line like /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaign_cron.php?
0
 
woolmilkporcCommented:
If you have the php CLI installed, try

php  /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaign_cron.php

If not, you will need your web server to run that script.

php CLI should be a bit faster than lynx + apache.
0
 
EMB01Author Commented:
Hey, I can open a new question if need be; but when I run it in PHP I get a bunch of errors. Do I need to change permissions or run the command with some flags?
PHP Warning:  require_once(): SAFE MODE Restriction in effect.  The script whose uid is 10001 is not allowed to access /usr/share/pear/Mail.php owned by uid 0 in /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaigns_cron.php on line 11
PHP Warning:  require_once(/usr/share/pear/Mail.php): failed to open stream: Success in /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaigns_cron.php on line 11
PHP Fatal error:  require_once(): Failed opening required '/usr/share/pear/Mail.php' (include_path='.:') in /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaigns_cron.php on line 11
0
 
woolmilkporcCommented:
Take care that the user with ID 10001 has access to  /usr/share/pear/Mail.php.
Check group ownership with 'ls -l /usr/share/pear/Mail.php' and put the user (10001) in the same group that script belongs to -
'usermod -a -G [group] [user]
Additionally make /usr/share/pear/Mail.php group-accessible (if it isn't already) by issuing 'chmod g+rx /usr/share/pear/Mail.php '
 
0
 
EMB01Author Commented:
Here's the output:
-rw-r--r-- 1 root root 8934 Feb  7 12:00 /usr/share/pear/Mail.php

I'm not 100% sure what the [group] variable is from:
usermod -a -G [group] [user]

Can I skip that part and simply make it group-accessible with:
chmod g+rx /usr/share/pear/Mail.php

Is using PHP that much faster, or will is the difference between PHP and Lynx even noticeable?

Thanks for your continued help.
0
 
woolmilkporcCommented:
OK, just read from your post that it is PHP SAFE MODE.
This means that php scripts are only allowed to access files belonging to the same owner/group as the script itself.
I don't know if it's possible for you to change owner/group of /usr/share/pear/Mail.php to be the same as the ones of /var/www/vhosts/emarketbuilders.com/httpdocs/admin/send_campaign_cron.php, but this would be a solution.
You can also switch off SAFE MODE (beginning with PHP 6 it's gone anyway.
As for speed - php CLI should be only a bit faster, but I guess one can't tell exactly without testing.
wmp
 


 
0
 
EMB01Author Commented:
According to my Plesk control panel, safe mode is off... I think I'll just use Lynx for, now and work the PHP thing out later as execution time becomes a larger issue.

Regarding the Lynx method, I keep getting emails everytime the script is run like "Cron <emarketbuilders@emarketbuilders> lynx -dump http://www.emarketbuilders.com/admin/send_campaigns_cron.php" and there won't be anything in the message. Can I shut these off by changing my current command which is "lynx -dump http://www.emarketbuilders.com/admin/send_campaigns_cron.php

Note: When I clear the -dump flag, it says "Your Terminal type is unknown! ..."
0
 
woolmilkporcConnect With a Mentor Commented:
Simply change your crontab entry to read
. . . . .  lynx -dump http://www.emarketbuilders.com/admin/send_campaign_cron.php >/dev/null 2>&1
That should do the trick.
safe mode might be off for your web server's php, but it might be enabled for your php CLI binary.

 
0
 
EMB01Author Commented:
Thanks, again for your outstanding support.
0
 
EMB01Author Commented:
Sorry it took so long to accept. I didn't realize this question was still open, somehow... Best wishes!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.