In linux, cron runs the php Program-Linux Enterprise Application-Linux server application information. The following is a detailed description. Recently I encountered a problem: I need to trigger a php script to send an email to me regularly. However, this script is a part of another script. It uses many mongodes commands and many library files use the mongodes command.
In general, there is nothing to say to trigger a php script. What you need to do is to set the following crontab on the server:
/Bin/local/php/path/to/your/php/script. php
That's it. Whether you want it or not, the script. php file will be automatically run by crontab.
However, the problem arises: When bash runs a cron, it won't pass through Apache. Of course, there are also its parameters, such as include_paths. Therefore, php will find the file in the/bin/local/php Directory. Of course, the file cannot be found.
In this case, follow these steps:
Enter the following command on the terminal to obtain the path of the sh and lynx programs:
Whereis sh
Whereis lynx
Or
Which sh
Which lynx
If you enter one, the path you want will be returned. If your system does not have lynx, try links, w3m, or links2. These are other text model browsers. These browsers will run your scripts.
Then you need to create a sh file and use it to call the PHP file through lynx. Assume that your server has installed lynx, THE sh path is/bin/sh, And the lynx path is/usr/local/bin/lynx.
#! /Bin/sh
/Usr/local/bin/lynx-source http://www.yoursite.com/folder/script.php
Note the exclamation point
Save this script as a cron-lynx.sh
Save it to a location you can find, for example:
/Usr/www/yourdirectory/sh_scripts/
I personally prefer to put it in the root directory of the website.
Then create a script. php file. When cron is running, it will be called through lynx. This file can be accessed through a browser. This is simple:
// I'm assuming you 've ve already set your include path
Include ('includes/stuff/another_script.inc ');
Another_program ();
?>
Then I edit the crontab of the host, as shown below.
/Bin/sh/usr/www/yourdirectory/sh_scripts/cron-lynx.sh
There is a space between/bin/sh and/usr. In this way, you can set up your sh file and PHP file correctly.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service