• <small id='9tkLy'></small><noframes id='9tkLy'>

    <tfoot id='9tkLy'></tfoot>

      <legend id='9tkLy'><style id='9tkLy'><dir id='9tkLy'><q id='9tkLy'></q></dir></style></legend>

        <bdo id='9tkLy'></bdo><ul id='9tkLy'></ul>

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

      1. 在 Ubuntu 上为 php 执行 Cron 作业

        时间:2023-08-17
        • <i id='VyPIR'><tr id='VyPIR'><dt id='VyPIR'><q id='VyPIR'><span id='VyPIR'><b id='VyPIR'><form id='VyPIR'><ins id='VyPIR'></ins><ul id='VyPIR'></ul><sub id='VyPIR'></sub></form><legend id='VyPIR'></legend><bdo id='VyPIR'><pre id='VyPIR'><center id='VyPIR'></center></pre></bdo></b><th id='VyPIR'></th></span></q></dt></tr></i><div id='VyPIR'><tfoot id='VyPIR'></tfoot><dl id='VyPIR'><fieldset id='VyPIR'></fieldset></dl></div>
        • <legend id='VyPIR'><style id='VyPIR'><dir id='VyPIR'><q id='VyPIR'></q></dir></style></legend>

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

                <tbody id='VyPIR'></tbody>

                <bdo id='VyPIR'></bdo><ul id='VyPIR'></ul>

                  <tfoot id='VyPIR'></tfoot>

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

                  问题描述

                  我在服务器上使用 Ubuntu,我使用 Putty 访问.我想为我的 php 站点创建 cronjobs.我怎样才能做到这一点?

                  I'm using Ubuntu on the server and I'm using Putty to access. I want to create cronjobs for my php site. How can I do this?

                  推荐答案

                  如果您的意思是希望您的 php 站点执行一些常规任务,则有两种可能的方法.

                  If you mean that you want your php site to do some regular tasks, there are two possible ways.

                  1) 您使用 cron 定期拉取某个页面.您可以使用基于文本的浏览器执行此操作,例如猞猁.你像这样拉你的脚本:

                  1) You use cron to pull a certain page regularly. You can do this with a text-based browser, e.g. lynx. You pull your script like this:

                  * * * * */usr/bin/lynx http://yourhost.com/cron.php -dump >/dev/null

                  (这将每分钟调用一次.这样您就可以在应用程序中构建自己的时间表)

                  (This will call it every minute. That way you can build your own schedule inside your application)

                  2) 你用命令行 php 解释器调用你的脚本:

                  2) You call your script with the command line php interpreter:

                  <代码>* * * * */usr/bin/php/path/to/cron.php >/dev/null

                  通常解决方案二更好.但是,您需要访问该框.如果您无法在主机上安装 cron,则解决方案一中的 cron 可以从不同的主机触发.

                  Generally solution two is better. However you will need access to the box. The cron in solution one can be triggered from a different host, if you cannot install crons on the host.

                  还要注意使用命令行版本的 php 的常见陷阱.在 debian(以及可能的其他系统)上,可能有单独的 php.ini 文件用于 cgi、cli 和 mod_php.如果您自定义了配置,请确保命令行 php 使用的是正确的配置.您可以使用以下方法进行测试:

                  Also beware of a common pitfall using the command line version of php. On debian (and potentially other systems) there may be seperate php.ini files for cgi, cli and mod_php. If you have customized your configuration make sure that the command line php is using the correct one. You can test this with:

                  <代码>/usr/bin/php -i |少

                  为了回应 dimo 的评论,我做了一些基准测试.我用 lynx、wget 和 php-cli 调用了一个简单的本地 php 脚本(它只是回应test")1000 次:

                  In response to the comment by dimo i made some benchmarks. I called a simple local php script (which just echos "test") 1000 times with lynx, wget and php-cli:

                  kbsilver:temp kbeyer$ time . wget.sh
                  
                   real 0m14.223s
                   user 0m2.906s 
                   sys 0m6.335s
                  
                  (Command: wget -O /dev/null "localhost/test.php"; 2> /dev/null) 
                  
                  kbsilver:temp kbeyer$ time . lynx.sh 
                  
                  real 0m26.511s 
                  user 0m5.789s 
                  sys 0m9.467s 
                  
                  (Command: lynx -dump "localhost/test.php"; > /dev/null) 
                  
                  
                  
                  
                  kbsilver:temp kbeyer$ time . php_cli.sh 
                  
                  real 0m54.617s 
                  user 0m28.704s 
                  sys 0m18.403s 
                  
                  (Command: /opt/local/bin/php /www/htdocs/test.php > /dev/null) 
                  

                  服务器是 lighttpdphp(fastcgi) 带有 apc(在 Mac OS X 上).

                  Server is lighttpd, php(fastcgi) with apc (on Mac OS X).

                  事实证明,就速度而言,wget 确实是这项工作的最佳工具.

                  It turns out that indeed wget is the best tool for the job regarding speed.

                  所以 php-cli 的结果并不令人惊讶,因为其他方法重用了一个已经运行的带有操作码缓存的 php 线程.

                  So the result of php-cli is not that suprising as the other methods reuse an already running php thread with opcode cache.

                  因此,使用 php-cli 的唯一真正优势是安全性,因为脚本将无法从外部访问,因为您可以将其放在 docroot 之外.

                  So the only real advantage of using php-cli is security as the script will not be available from outside as you can put it outside the docroot.

                  (这个测试显然不是100%准确,但在我看来差异还是很明显的)

                  (This test is obviously not 100% accurate, but the differences are quite obvious in my opinion)

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

                  上一篇:Cron 作业 $_SERVER 问题 下一篇:如何每分钟多次运行 Cronjobs?

                  相关文章

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

                2. <small id='HuDWq'></small><noframes id='HuDWq'>

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

                  1. <tfoot id='HuDWq'></tfoot>