简体   繁体   English

cron由于正斜杠而无法运行PHP

[英]cron won't run PHP because of forward slash

Alright, so I've got a cron job that is supposed to run a PHP file every minute, I'm hitting the file and getting an error that I'm not sure how to fix exactly; 好吧,所以我有一个cron作业,该作业应该每分钟运行一个PHP文件,我在打该文件时遇到一个错误,即我不确定如何正确修复。 the server (Debian) will not recognize PHP's include if there is a '/' located anywhere in the link. 如果链接中任何位置都有“ /”,则服务器(Debian)将无法识别PHP的包含。

I've been searching for an answer for this for about an hour and a half and keep running up nothing. 我一直在寻找答案,大约一个半小时,然后什么也没跑。 Hopefully you guys could lend me a hand 希望你们能帮我一下

Please use absolute file path. 请使用绝对文件路径。 If the "include" files are relative to the "main.php", you can use 如果“ include”文件是相对于“ main.php”的,则可以使用

include(dirname(__FILE__)."/mysubdir/myincfile.php");

The more elegant way about filesystem "slashes" is to use DIRECTORY_SEPARATOR , eg, 关于文件系统“斜杠”的更优雅的方法是使用DIRECTORY_SEPARATOR ,例如,

include(dirname(__FILE__).DIRECTORY_SEPARATOR."mysubdir".DIRECTORY_SEPARATOR."myincfile.php");

The better yet way to handle directories is to "define" them: 处理目录的更好的方法是“定义”它们:

if(!defined('MYROOTDIR'))
{ 
   define('MYROOTDIR',(dirname(__FILE__).DIRECTORY_SEPARATOR."mysubdir"));
}
include(MYROOTDIR."myincfile.php");

Thank you, 谢谢,
Tom 汤姆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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