简体   繁体   中英

PHP constant not defined when using cli but works via apache

I have a scenario where a static function in an included file will see my defined values if I trigger that code via web-request but when the exact same code is triggered via a cron fired schedule the defined values are not seen as defined. I have reduced my code scenario to the simplest possible form as follows:

Update I put an error_log(print_r(get_defined_constants(true),true)); in the file and compared the results between a web execution and a cron execution and the only thing different is my missing constant on the cron side and the pcntl extension constants on the cron web side

note : all web requests require this settings file and have no issue
note : I have other scheduled files that see the defined values
note : I have other web files that utilize this class and its functions without issue.

confirmed : The settings file is included
confirmed : The function is being called

I feel like I'm missing something completely obvious or highly esoteric.

//-- settings file
...
define("NEED_THIS_CONST","DOODLYDOO");
...
//-- class file
class vendor {
  public static function dothis() {
    error_log("reached the file");
    if(!defined("NEED_THIS_CONST")) {
      error_log("not defined");
    else
      error_log("defined");
    }
  }
}
//-- requested file
...
require_once("settings.php");
include_once("vendor.php");
vendor::dothis();

The issue has been resolved. At some point I had copied the settings file (a hidden file) to my home directory to scp it, and for some reason this script (not in the same path) was using that settings file when triggered from cron, when I removed that copy (not a link) cron instantly started using the live file. I still dont know why that copy was used as the actual include pathing is relative pathing to the absolute codebase root that wouldn't find that file anyway. I'm lost as to the how, shadow file handle? On Linux? Never heard of that. It works now though.

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