• <bdo id='ZezgL'></bdo><ul id='ZezgL'></ul>

        <tfoot id='ZezgL'></tfoot>

        <i id='ZezgL'><tr id='ZezgL'><dt id='ZezgL'><q id='ZezgL'><span id='ZezgL'><b id='ZezgL'><form id='ZezgL'><ins id='ZezgL'></ins><ul id='ZezgL'></ul><sub id='ZezgL'></sub></form><legend id='ZezgL'></legend><bdo id='ZezgL'><pre id='ZezgL'><center id='ZezgL'></center></pre></bdo></b><th id='ZezgL'></th></span></q></dt></tr></i><div id='ZezgL'><tfoot id='ZezgL'></tfoot><dl id='ZezgL'><fieldset id='ZezgL'></fieldset></dl></div>
        <legend id='ZezgL'><style id='ZezgL'><dir id='ZezgL'><q id='ZezgL'></q></dir></style></legend>

        <small id='ZezgL'></small><noframes id='ZezgL'>

        相对路径在 cron PHP 脚本中不起作用

        Relative path not working in cron PHP script(相对路径在 cron PHP 脚本中不起作用)

          <bdo id='7CwmM'></bdo><ul id='7CwmM'></ul>
            <tfoot id='7CwmM'></tfoot>
              <tbody id='7CwmM'></tbody>

            <small id='7CwmM'></small><noframes id='7CwmM'>

            <legend id='7CwmM'><style id='7CwmM'><dir id='7CwmM'><q id='7CwmM'></q></dir></style></legend>

                • <i id='7CwmM'><tr id='7CwmM'><dt id='7CwmM'><q id='7CwmM'><span id='7CwmM'><b id='7CwmM'><form id='7CwmM'><ins id='7CwmM'></ins><ul id='7CwmM'></ul><sub id='7CwmM'></sub></form><legend id='7CwmM'></legend><bdo id='7CwmM'><pre id='7CwmM'><center id='7CwmM'></center></pre></bdo></b><th id='7CwmM'></th></span></q></dt></tr></i><div id='7CwmM'><tfoot id='7CwmM'></tfoot><dl id='7CwmM'><fieldset id='7CwmM'></fieldset></dl></div>

                  本文介绍了相对路径在 cron PHP 脚本中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果 PHP 脚本作为 cron 脚本运行,如果使用相对路径,则包含通常会失败.例如,如果您有

                  If a PHP script is run as a cron script, the includes often fail if relative paths are used. For example, if you have

                  require_once('foo.php');
                  

                  在命令行上运行时会找到文件 foo.php,但在从 cron 脚本运行时不会找到.

                  the file foo.php will be found when run on the command line, but not when run from a cron script.

                  对此的典型解决方法是先将 chdir 指向工作目录,或使用绝对路径.但是,我想知道导致这种行为的 cron 和 shell 之间有什么不同.为什么在 cron 脚本中使用相对路径会失败?

                  A typical workaround for this is to first chdir to the working directory, or use absolute paths. I would like to know, however, what is different between cron and shell that causes this behavior. Why does it fail when using relative paths in a cron script?

                  推荐答案

                  从 cron 运行时,脚本的工作目录可能不同.此外,关于 PHP 的 require() 和 include() 存在一些混淆,这导致了工作目录真正是问题所在的混淆:

                  The working directory of the script may be different when run from a cron. Additionaly, there was some confusion about PHPs require() and include(), which caused confusion about the working directory really being the problem:

                  include('foo.php') // searches for foo.php in the same directory as the current script
                  include('./foo.php') // searches for foo.php in the current working directory
                  include('foo/bar.php') // searches for foo/bar.php, relative to the directory of the current script
                  include('../bar.php') // searches for bar.php, in the parent directory of the current working directory
                  

                  这篇关于相对路径在 cron PHP 脚本中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Is PHP or PHP based web framework stateful or stateless?(PHP 或基于 PHP 的 Web 框架是有状态的还是无状态的?)
                  How to parse django style template tags(如何解析 django 样式模板标签)
                  What is a good setup for editing PHP in Emacs?(在 Emacs 中编辑 PHP 的好设置是什么?)
                  How to check whether specified PID is currently running without invoking ps from PHP?(如何在不从 PHP 调用 ps 的情况下检查指定的 PID 当前是否正在运行?)
                  What#39;s the difference between escapeshellarg and escapeshellcmd?(escapeshellarg 和escapeshellcmd 有什么区别?)
                  php in background exec() function(php 后台 exec() 函数)

                      <small id='jZkFT'></small><noframes id='jZkFT'>

                    1. <legend id='jZkFT'><style id='jZkFT'><dir id='jZkFT'><q id='jZkFT'></q></dir></style></legend>
                        <tbody id='jZkFT'></tbody>
                      <tfoot id='jZkFT'></tfoot>
                      • <bdo id='jZkFT'></bdo><ul id='jZkFT'></ul>
                        • <i id='jZkFT'><tr id='jZkFT'><dt id='jZkFT'><q id='jZkFT'><span id='jZkFT'><b id='jZkFT'><form id='jZkFT'><ins id='jZkFT'></ins><ul id='jZkFT'></ul><sub id='jZkFT'></sub></form><legend id='jZkFT'></legend><bdo id='jZkFT'><pre id='jZkFT'><center id='jZkFT'></center></pre></bdo></b><th id='jZkFT'></th></span></q></dt></tr></i><div id='jZkFT'><tfoot id='jZkFT'></tfoot><dl id='jZkFT'><fieldset id='jZkFT'></fieldset></dl></div>