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

      <bdo id='Zq0h8'></bdo><ul id='Zq0h8'></ul>
  1. <legend id='Zq0h8'><style id='Zq0h8'><dir id='Zq0h8'><q id='Zq0h8'></q></dir></style></legend>

    <tfoot id='Zq0h8'></tfoot>

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

      php cron作业没有运行

      php cron job not running(php cron作业没有运行)
        <tfoot id='mv4cg'></tfoot>

      1. <legend id='mv4cg'><style id='mv4cg'><dir id='mv4cg'><q id='mv4cg'></q></dir></style></legend>

            <tbody id='mv4cg'></tbody>
            <bdo id='mv4cg'></bdo><ul id='mv4cg'></ul>

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

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

                本文介绍了php cron作业没有运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                root@xx:/var/www/test# which php
                /usr/bin/php
                

                <小时>

                root@xx:/var/www/test# ls -la
                total 16
                drwxrwxrwx 2 root root 4096 Nov 14 09:37 .
                drwxrwxrwx 6 root root 4096 Nov 13 15:51 ..
                -rwxrwxrwx 1 root root  153 Nov 14 09:35 test.php
                

                这是我的 test.php 文件:

                <?php
                $my_file = 'file.txt';
                $handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); //implicitly creates file
                

                这是crontab -l的输出:

                #this is ok
                * * * * * touch /tmp/hello
                #this only creates an empty php_result.log
                * * * * * /usr/bin/php /var/www/test/test.php > /tmp/php_result.log
                

                <小时>

                root@xx:/var/www/test# php -v
                PHP 5.4.34-0+deb7u1 (cli) (built: Oct 20 2014 08:50:30) 
                

                cron 作业不会运行,问题出在 php 上.如果我手动运行该文件,一切正常.

                The cron job will not run, and the problem is with php. If i run the file manually, all works well.

                php test.php
                

                相关问题:为什么crontab不执行我的PHP脚本?.

                推荐答案

                您需要在脚本中使用完整路径.否则,cron 将不知道该文件在哪里.

                You need to use full paths in your scripts. Otherwise, cron won't know where is that file.

                所以代替

                $my_file = 'file.txt';
                

                使用

                $my_file = '/path/to/file.txt';
                

                可能您将 file.txt 存储在 / 的某个位置.

                Probably you were getting file.txt stored somewhere in /.

                注意 crontab 在有限的环境中运行,因此它不能假设任何有关路径的信息.这就是为什么您还必须提供 php 等的完整路径.

                Note crontab runs in a limited environment, so it cannot assume anything regarding to paths. That's why you also have to provide the full path of php, etc.

                来自 排查 cron 作业的常见问题:

                使用相对路径.如果您的 cron 作业正在执行某个脚本种类,您必须确保在该脚本中仅使用绝对路径.例如,如果您的脚本位于/path/to/script.phpand你试图在同一目录中打开一个名为 file.php 的文件,您不能使用相对路径,例如 fopen(file.php).该文件必须从其绝对路径调用,如下所示:fopen(/path/to/file.php).这是因为 cron 作业不一定从以下目录运行脚本所在的位置,因此必须专门调用所有路径.

                Using relative paths. If your cron job is executing a script of some kind, you must be sure to use only absolute paths inside that script. For example, if your script is located at /path/to/script.phpand you're trying to open a file called file.php in the same directory, you cannot use a relative path such as fopen(file.php). The file must be called from its absolute path, like this: fopen(/path/to/file.php). This is because cron jobs do not necessarily run from the directory in which the script is located, so all paths must be called specifically.

                这篇关于php cron作业没有运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                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() 函数)
                  <bdo id='cuFva'></bdo><ul id='cuFva'></ul>
                  1. <i id='cuFva'><tr id='cuFva'><dt id='cuFva'><q id='cuFva'><span id='cuFva'><b id='cuFva'><form id='cuFva'><ins id='cuFva'></ins><ul id='cuFva'></ul><sub id='cuFva'></sub></form><legend id='cuFva'></legend><bdo id='cuFva'><pre id='cuFva'><center id='cuFva'></center></pre></bdo></b><th id='cuFva'></th></span></q></dt></tr></i><div id='cuFva'><tfoot id='cuFva'></tfoot><dl id='cuFva'><fieldset id='cuFva'></fieldset></dl></div>

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

                    • <tfoot id='cuFva'></tfoot>

                      <legend id='cuFva'><style id='cuFva'><dir id='cuFva'><q id='cuFva'></q></dir></style></legend>
                        <tbody id='cuFva'></tbody>