简体   繁体   English

作为cron作业运行时,访问PHP包括以上webroot

[英]Accessing PHP includes above webroot when running as cron job

I'm trying to use a PHP script with sensitive information so I'm using includes to host the passwords above the webroot. 我正在尝试将PHP脚本与敏感信息一起使用,因此我正在使用include将密码托管在webroot上方。

The script works fine run via the browser, but when I run it as a crob job it generates error messages regarding includes. 该脚本可以通过浏览器正常运行,但是当我将其作为crob作业运行时,它会生成有关包含的错误消息。

The open_basedir setting is: /var/www/vhosts/xxx/:/tmp/ -- wondering if that's relevant here? open_basedir设置为:/ var / www / vhosts / xxx /:/ tmp /-想知道在这里是否相关?

Grateful for any suggestions on how to resolve this or workarounds. 感谢您提供有关如何解决此问题或解决方法的建议。

PHP Warning:  include(../includes.php): failed to open stream: No such file or directory in /var/www/vhosts/xxx.com/httpdocs/linkedin_status.php on line 6
PHP Warning:  include(../includes.php): failed to open stream: No such file or directory in /var/www/vhosts/xxx.com/httpdocs/linkedin_status.php on line 6
PHP Warning:  include(): Failed opening '../includes.php' for inclusion (include_path='.:') in /var/www/vhosts/xxx.com/httpdocs/linkedin_status.php on line 6
PHP Notice:  Use of undefined constant API_KEY - assumed 'API_KEY' in /var/www/vhosts/xxx.com/httpdocs/linkedin_status.php on line 88
PHP Notice:  Use of undefined constant SCOPE - assumed 'SCOPE' in /var/www/vhosts/xxx.com/httpdocs/linkedin_status.php on line 89
PHP Notice:  Use of undefined constant REDIRECT_URI - assumed 'REDIRECT_URI' in /var/www/vhosts/xxx.com/httpdocs/linkedin_status.php on line 91

这总是对我有用...

require_once("/full/path/to/your/file/includes.php");

What you are probably experiencing is that the Cronjob is using a different php.ini, and thus using different settings. 您可能正在体验的是Cronjob使用不同的php.ini,因此使用了不同的设置。 To confirm this you can create a php script that writes phpinfo(); 为了确认这一点,您可以创建一个编写phpinfo();的php脚本phpinfo(); results to a file. 结果到文件中。 In the output you will see which php.ini is being used. 在输出中,您将看到正在使用哪个php.ini。

What you can do to fix this is either: 您可以采取以下措施来解决此问题:

  • When executing the cronjob specify which php.ini is to be used. 执行cronjob时,指定要使用的php.ini。
  • Run the cronjob via a wget command that actually executes the script via the webserver, like a browser. 通过wget命令运行cronjob,该命令实际上是通过网络服务器(如浏览器)执行脚本的。 Wget is a commannd prompt tool (not PHP!) that calls a url from the internet and writes it to screen or file. Wget是一种命令提示符工具(不是PHP!),它从Internet调用URL并将其写入屏幕或文件。

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

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