<tfoot id='hEaUs'></tfoot>
    • <bdo id='hEaUs'></bdo><ul id='hEaUs'></ul>

    <legend id='hEaUs'><style id='hEaUs'><dir id='hEaUs'><q id='hEaUs'></q></dir></style></legend>
  • <small id='hEaUs'></small><noframes id='hEaUs'>

        <i id='hEaUs'><tr id='hEaUs'><dt id='hEaUs'><q id='hEaUs'><span id='hEaUs'><b id='hEaUs'><form id='hEaUs'><ins id='hEaUs'></ins><ul id='hEaUs'></ul><sub id='hEaUs'></sub></form><legend id='hEaUs'></legend><bdo id='hEaUs'><pre id='hEaUs'><center id='hEaUs'></center></pre></bdo></b><th id='hEaUs'></th></span></q></dt></tr></i><div id='hEaUs'><tfoot id='hEaUs'></tfoot><dl id='hEaUs'><fieldset id='hEaUs'></fieldset></dl></div>
      1. 使用 Zend 框架安全地运行 Cron 作业

        时间:2023-10-02

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

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

              <legend id='z9fu2'><style id='z9fu2'><dir id='z9fu2'><q id='z9fu2'></q></dir></style></legend>

                <bdo id='z9fu2'></bdo><ul id='z9fu2'></ul>
                  <tbody id='z9fu2'></tbody>
                <tfoot id='z9fu2'></tfoot>
                1. 本文介绍了使用 Zend 框架安全地运行 Cron 作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我看过很多关于 cron 和 ZF 的帖子,但大多数解决方案都让工作运行,以供公众触发.

                  I've seen plenty of posts about cron and ZF but most of the solutions leave the job to be run available to triggering by the public.

                  如果你想设置一个只能由cron运行的动作怎么办?不是某个匿名用户,也不是必须登录的人?

                  What if you want to set up an action that can ONLY be run by cron? Not by some anonymous user and not by someone that has to log in?

                  我使用的解决方案涉及将一个文件放在我的网络根目录之外,让它引导足够的 ZF 来使用我需要的东西(比如,我不需要视图),然后从 cron 中点击它.我的问题是,这是一种最佳实践"方式吗?如果您需要使代码可通过网络访问,但仍需要防止随机用户找到并运行它,该怎么办?

                  The solution I am using involved putting a file outside of my web root, having it bootstrap enough of the ZF to use what I need (like, I don't need the view) and then hit that from cron. My questions are, is this a "best practice" way to do this? What if you needed to make the code accessible over the web but still need to prevent random users from finding and running it?

                  为了说明,这是我正在为从 php 命令行和在同一台服务器上运行的 cron 作业执行的操作(有效),如下所示:

                  For illustration, here is what I am doing (that works) for a cron job run from the php command line, and on the same server, something like this:

                  * 10 * * * php /Apps/ZF/cronjobs/crontest.php
                  

                  Webroot 是:/Apps/ZF/someproject/

                  crontest.php:

                  crontest.php:

                  <?php
                  ini_set('include_path', ini_get('include_path') . ':/Apps/ZF/someproject/library');
                  
                  define('APPLICATION_PATH','/Apps/ZF/someproject/application');
                  define('APPLICATION_ENVIRONMENT','test');
                  
                  //Include the loader (for loading ZF resources)
                  require_once 'Zend/Loader.php';
                  
                  //Include the model (to access the Sites model in this case)
                  require_once(APPLICATION_PATH . '/models/Planets.php');
                  
                  Zend_Loader::registerAutoload();
                  
                  $configuration = new Zend_Config_Ini(
                      APPLICATION_PATH . '/config/config.ini',
                      APPLICATION_ENVIRONMENT
                  );
                  
                  // DB adapter
                  $dbAdapter = Zend_Db::factory($configuration->database);
                  
                  // DB table setup
                  Zend_Db_Table_Abstract::setDefaultAdapter($dbAdapter);
                  
                  // Whatever code we want to run... 
                  $test = new Model_Planets();
                  
                  $test->fetchEntries();
                  
                  Zend_Debug::dump($test);
                  ?>
                  

                  所以,正如我所说,这行得通,所以我不是在找人给我写一个解决方案……只是对把这个做得更好"感到好奇.另外,如果我需要通过网络访问它但仍然希望它只能由 cron 运行怎么办?让它更灵活怎么样(因为在这里我硬编码了一些我怀疑可以变得更加动态的路径)?

                  So, as I said, this works so I'm not looking for someone to write me a solution... just curious about doing this "better". Also, what if I needed this to be accessible via the web but still want to keep it only runnable by cron? What about making it more flexible (because here I am hard coding a few paths that I suspect could be made more dynamic)?

                  我假设我可以列出允许的服务器列表,然后使用 $_SERVER['REMOTE_ADDR'] 进行测试?

                  I assume I could make a list of permitted servers, then test that with $_SERVER['REMOTE_ADDR']?

                  大家怎么看?建议?我一个人工作,所以我没有同事可以在这件事上寻求帮助......在某种程度上,我的同事就是这样.

                  What do you all think? Suggestions? I work alone so I have no colleague to ask for help on this... SO is my colleague, in a way.

                  推荐答案

                  一种方法是设置环境变量.

                  One way is to set an environmental variable.

                  所以在你的 crontab 中

                  So in your crontab

                  SCRIPT_RUN_ENV=cron
                  * * * * * foo.php // Whatever your line is
                  

                  然后,在应用程序中,只需检查:

                  Then, in the application, just check that:

                  if (get_env('SCRIPT_RUN_ENV') != 'cron') {
                      echo "Program cannot be run manually
                  ";
                      exit(1);
                  }
                  

                  现在,任何人都可以将他们的环境变量设置为该值并成功运行 cron,但它应该停止琐碎的运行(或意外)...

                  Now, anyone can set their environmental variable to that value and successfully run the cron, but it should stop the trivial running (or accidental)...

                  但还要注意,任何可以在服务器上编辑环境变量的人都可以执行它,所以没有真正的方法从那个角度来保护它(至少没有一个是自动化的)......还值得注意的是你无法通过 HTTP 注入环境变量.

                  But also note that anyone who can edit the environmental variable on the server can already execute it, so there's no real way to secure it from that angle (none that are automated at least)... It's also worth noting that you cannot inject an environmental variable through HTTP.

                  这篇关于使用 Zend 框架安全地运行 Cron 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 PECL 操作系统在 PHP 5.1.6 上安装 PDO_MYSQL:Ubu 下一篇:如何在 Zend 框架中使用 GROUP_CONCAT?

                  相关文章

                  最新文章

                  <tfoot id='u7kyO'></tfoot>
                  <legend id='u7kyO'><style id='u7kyO'><dir id='u7kyO'><q id='u7kyO'></q></dir></style></legend>

                  1. <small id='u7kyO'></small><noframes id='u7kyO'>

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

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