Cron 作业 $_SERVER 问题
我想运行一个 cron 作业.我的应用程序是用 PHP 和 Mysql 开发的.
I want to run a cron job. My application is developed in PHP and Mysql.
在浏览器中,如果我在编码中使用 $_SERVER[HTTP_HOST]
,它工作正常.但是,如果我在 cron 作业中使用相同的东西,则会出错.
In browser if i use $_SERVER[HTTP_HOST]
in coding, it works fine. But if I use the same thing in cron job it is giving errors.
任何机构都可以提出解决此问题的建议吗?
Can any body give suggestion to fix this?
推荐答案
$_SERVER['HTTP_HOST']
从 cronjob 运行时未填充,文件未通过 HTTP 访问.
$_SERVER['HTTP_HOST']
is not populated when running it from a cronjob, the file is not accessed via HTTP.
您要么必须对主机进行硬编码,要么通过命令行参数传递它并通过 $_SERVER['argv']
数组访问它.
You will either have to hardcode the Host or pass it via a command line argument and access it via the $_SERVER['argv']
array.
相关文章