Contents
|
Some PHP scripts are designed to be run from a web browser; if this is the case for your script, you should select http as the command language. Other PHP scripts are designed to be run from PHP directly on the server; if this is the case for your script, you should select php as the command language.
Selecting the incorrect command language for your cron job can cause it to fail to execute properly or to obtain invalid results or output. However, choosing the correct command language is entirely based upon the code in the PHP script; it's therefore recommended to request assistance from the developer of the PHP script if you are unsure of the proper way it should be run.
For more information about the command language and setting up a cron job, please see How do I schedule a cron job?
If you select php as the command language for your cron job, relative paths may not work. This is because some PHP scripts expect to be run from the directory where they are stored, and due to the nature of our Cloud Sites platform they will be run from another location. This means including or requiring files from a relative path may result in errors such as:
PHP Warning: include(../example.php): failed to open stream: No such file or directory
A relative include looks something like this:
include('example.php');
Or this:
include('../example.php');
If you receive an error when using relative paths, this does not necessarily indicate that the file does not exist at the location you expect to find it; it just means that the PHP script is not being executed from the current directory, and so the script is looking in the wrong directory to find those files.
To correct this problem, you could use the absolute path to reference any files in your script. An absolute include looks something like this:
include('/mnt/stor1-wc1-dfw1/123456/www.example.com/web/content/example.php');
You will want to change the path in the example above to use your website's absolute path to the file being included. Please see this article to locate your website's absolute path.
Another solution is to indicate in the PHP script that you would like files to be referenced from the script's current working directory. To do this, you could use a snippet of code such as the following near the top of your script:
chdir(dirname(__FILE__));
This changes the current working directory to match the script's directory by using the __FILE__ magic constant.
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

1 Comment
Thanks so much for this.
That one little line, chdir(dirname(__FILE__)); has solved everything. I really didn't want to have to use absolute paths. You always miss a couple when moving from a dev server to the live one :P
Add new comment