简体   繁体   中英

Cronjob not working - trying to run PHP script

I am running a cronjob that runs a PHP script to do a couple of things; first, it opens the database and stores the contents of the tables into memcache; second it creates a Javascript file that is basically a couple of arrays so that the client browser can do a lot of the work and save the server from being overloaded. This is newly added.

The script runs manually very well, and for over a year it has done its job, updating memcache every 10 minutes. The Javascript file add on is the big problem here; the cronjob s/b creating a new, updated edition of this file every 10 minutes, but appears to be not working unless I run it manually from the command line.

I can check this by doing:

ls -al id_index.js  

and checking the timestamp in the file listing.

Is there some problem with creating a Javascript file from a script started by crontab?

Btw, the cronjob file entry looks like this:

# m h  dom mon dow   command
*/10 * * * * php /home/accountname/public_html/mc_store_arrays.php

Any and all help is appreciated.

由于cron环境很少定义可用的PATH环境变量,因此最有可能必须指定php cli解释器的绝对路径。

In which directory are you expecting the javascript file to be created? It probably is being created somewhere ... wherever cron's working directory happens to be when the script runs ( /root/ perhaps?). Make sure your output file is specified with an absolute path or with eg:

file_put_contents(__DIR__ . '/id_index.js', $content);

which will create the file based on the path of the php script that's running, rather than the path from which it was executed.

Try using LYNX (just the way you use a web browser);

Example: LYNX http://www.MyDomain.Com/MyScript.php?MyParameter=MyValue&And=SoOn

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM