$_SERVER[#39;DOCUMENT_ROOT#39;] does not work in the php script running through cron ($_SERVER[DOCUMENT_ROOT] 在通过 cron 运行的 php 脚本中不起作用)
问题描述
我使用 $_SERVER['DOCUMENT_ROOT']."/lib/sft_required.php";在 PHP 脚本中包含sft_required"文件.当我使用浏览器运行此文件时,它工作正常,但是当我将它作为 cron 作业运行时,它不起作用.我们通过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 运行 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 脚本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:$_SERVER['DOCUMENT_ROOT'] 在通过 cron 运行的 php 脚本中不起作用


- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01