Jump to content


This topic is now archived and is closed to further replies.


Unable to run a PHP script from a web-based Cron Job

Recommended Posts

My host has a very specific method for setting up cron jobs whereby the script needs to be accessible via http.  The support page has an article that details how to set this up if snippet of code wasn't developed for web-access (which is the case for all of mine) and as long as it was a 'curl' statement, I haven't had any problem... but now I'm running into a weird output because I'm trying to access a .php file .... and thus I come here seeking help :)

According to the Knowledge Base article I'm told to do the following (I used all the example file names/locations for testing).
1) Create a file "web.sh" w/in the cgi-bin directory and include the following code
#! /bin/sh
echo "Content-type: text/plain";
cd "${SITE_ROOT}/var/www/html";
echo "Script completed with exit code $?.";
exit 0;

2) Insert the command into the /bin/example.pl file (the command for the cron job to execute)
php /path_to_file/search/admin/spider.php -u http://www.___________.com/_realdeal/ -r

3) That's it for the setup, to test it I just go to http://www.______.com/cgi-bin/web.sh

When I do this I get one of two error messages.  "Exit Code: 126" showed up a few times until I changed the file permissions to "755".  Then, the following output is what I keep running into.
Status: 400
Content-type: text/html

<b>Security Alert!</b> The PHP CGI cannot be accessed directly.

<p>This PHP CGI binary was compiled with force-cgi-redirect enabled. This
means that a page will only be served up if the REDIRECT_STATUS CGI variable is
set, e.g. via an Apache Action directive.</p>
<p>For more information as to <i>why</i> this behaviour exists, see the <a href="http://php.net/security.cgi-bin">manual page for CGI security</a>.</p>
<p>For more information about changing this behaviour or re-enabling this webserver,
consult the installation file that came with this distribution, or visit
<a href="http://php.net/install.windows">the manual page</a>.</p>
Script completed with exit code 255.

I've gone to both URL's the output's suggested and haven't been able to make any sense of it.  I'm not even sure if a "php" forum is where I need to be inquiring; but I figured since this error's only shown up when trying to run a .php file, hell it'd be a good place to start.

I really appreciate any advise, tips, or solutions anyone might have.  Thanks everyone!

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.