/    Sign up×
Community /Pin to ProfileBookmark

Calling PHP with Cron

I am able to call a PHP script from the command line of Linux with the desired results, but when I call it as a Cron job it has various errors.

The Cron is:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/php -q /vservers/wheredidshegetit/htdocs/imap.php

I am thinking it’s a permissions issue. Maybe I have to tell it which user should run the script? I just figured Cron out this afternoon.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogMay 21.2008 — It could be an environment issue, as cron jobs typically do not have all the path and other environment variables set that you do in a shell environment. Possibly invoking it via the shell would help. The simplest thing might be to create a shell script that launches your PHP script, then simply call that script from cron, e.g.:

my_cron.sh:
<i>
</i>#!/usr/bin/sh
/usr/bin/php -q /vservers/wheredidshegetit/htdocs/imap.php

(Adjust the "/usr/bin/sh" in the first "shebang" line to point to whichever shell you want to use on your server.)

Then your cron would just be:
<i>
</i>0,5,10,15,20,25,30,35,40,45,50,55 * * * * /vservers/path/to/my_cron.sh
Copy linkTweet thisAlerts:
@auxoneauthorMay 21.2008 — Thanks for the help. I was actually trying some things and I stumbled on the solution. As you said, the path and environment variables were off. It was miss leading since it worked from command line, but when I reached deep inside my code I found a few places where I changes the references from relative to absolute (and fixed a few warnings) and it worked.
×

Success!

Help @auxone spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...