$ _SERVER ['DOCUMENT_ROOT']在通过cron运行的php脚本中不起作用 [英] $_SERVER['DOCUMENT_ROOT'] does not work in the php script running through cron

查看:288
本文介绍了$ _SERVER ['DOCUMENT_ROOT']在通过cron运行的php脚本中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用$ _SERVER ['DOCUMENT_ROOT']。/ lib / sft_required.php;以将'sft_required'文件包含在PHP脚本中。当我使用浏览器运行这个文件,它工作正常,但当我作为cron工作作业运行它不工作。

I use $_SERVER['DOCUMENT_ROOT']."/lib/sft_required.php"; to include the 'sft_required' file in a PHP script. When I run this file using browser, it works fine but when I run this as a cron job job, it does not work. It seems that the file is not included when we run the script through cron.

推荐答案

假设您直接通过cron运行脚本(而不是从由cronjob触发的HTTP请求访问的Web服务器(例如通过cron running wget)访问),那么它当然不起作用。

Assuming you are running the script directly through cron (as opposed to from a web server accessed by an HTTP request triggered by a cronjob (e.g. by cron running wget)), then of course it doesn't work.

没有服务器,因此未设置 $ _ SERVER

There is no server, so $_SERVER is not set.

这篇关于$ _SERVER ['DOCUMENT_ROOT']在通过cron运行的php脚本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆