• <small id='exaYw'></small><noframes id='exaYw'>

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

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

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

      1. 如何在 PHP 中的请求之间持久化对象

        How to persist objects between requests in PHP(如何在 PHP 中的请求之间持久化对象)
        <i id='8wQVj'><tr id='8wQVj'><dt id='8wQVj'><q id='8wQVj'><span id='8wQVj'><b id='8wQVj'><form id='8wQVj'><ins id='8wQVj'></ins><ul id='8wQVj'></ul><sub id='8wQVj'></sub></form><legend id='8wQVj'></legend><bdo id='8wQVj'><pre id='8wQVj'><center id='8wQVj'></center></pre></bdo></b><th id='8wQVj'></th></span></q></dt></tr></i><div id='8wQVj'><tfoot id='8wQVj'></tfoot><dl id='8wQVj'><fieldset id='8wQVj'></fieldset></dl></div>

          • <bdo id='8wQVj'></bdo><ul id='8wQVj'></ul>
              <tbody id='8wQVj'></tbody>

          • <tfoot id='8wQVj'></tfoot>

            <small id='8wQVj'></small><noframes id='8wQVj'>

                  <legend id='8wQVj'><style id='8wQVj'><dir id='8wQVj'><q id='8wQVj'></q></dir></style></legend>
                1. 本文介绍了如何在 PHP 中的请求之间持久化对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我过去一直在使用 rails、merb、django 和 asp.net mvc 应用程序.他们的共同点(与问题相关)是他们拥有设置框架的代码.这通常意味着创建持续存在的对象和状态,直到 Web 服务器被回收(例如设置路由,或检查哪些控制器可用等).

                  I've been using rails, merb, django and asp.net mvc applications in the past. What they have common (that is relevant to the question) is that they have code that sets up the framework. This usually means creating objects and state that is persisted until the web server is recycled (like setting up routing, or checking which controllers are available, etc).

                  据我所知,PHP 更像是一个 CGI 脚本,每次运行时都会被编译成一些字节码,而在发出请求后它会被丢弃.当然,您可以拥有会话,以便在来自同一用户的请求之间持久化数据,并且我看到有像 APC 这样的扩展,您可以使用它在服务器级别的请求之间持久化对象.

                  As far as I know PHP is more like a CGI script that gets compiled to some bytecode each time it's run, and after the request it's discarded. Of course you can have sessions, to persist data between requests from the same user, and as I see there are extensions like APC, with which you can persist objects between requests at the server level.

                  我的问题是:如何创建一个像 rails 之类的 PHP 应用程序?我的意思是一个应用程序在第一次请求时设置框架,然后在第二次和以后的请求中使用已经设置的对象.mod_php 中是否有一些内置的缓存设施?(例如,存储已执行 php 应用程序的编译字节码)还是使用 APC 或一些类似的扩展来解决这个问题的唯一方法?你会怎么做?

                  My question is: how can one create a PHP application that works like rails and such? I mean an application that on the first requests sets up the framework, then on the 2nd and later requests use the objects that are already set up. Is there some built in caching facility in mod_php? (for example that stores the compiled bytecode of the executed php applications) Or is using APC or some similar extensions the only way to solve this problem? How would you do it?

                  谢谢.

                  替代问题:如果我创建一个大型 PHP 应用程序,它的设置时间很长,但运行时间很短(如在上面提到的框架中),那么我应该如何缓存"已经设置的东西(这可能意味着很多事情,除了数据库连接,因为您已经在 PHP 中拥有持久连接).

                  Alternative question: if I create a large PHP application that has a very large set up time, but minor running time (like in the frameworks mentioned above) then how should I "cache" the things that are already set up (this might mean a lot of things, except for maybe the database connections, because for that you have persistent connections in PHP already).

                  为了证明大的设置时间是合理的:如果我使用 PHP 反射来检查哪些对象可用并据此设置运行时会怎样.进行大量反思通常很慢,但只需要做一次(并且只有在修改源代码时才重新评估).

                  To justify large set up time: what if I'm using PHP reflection to check what objects are available and set the runtime according to that. Doing a lot of reflection is usually slow, but one has to do it only once (and re-evaluate only if the source code is modified).

                  那似乎是APC.很高兴知道它会自动缓存字节码.

                  It seems it's APC then. The fact that it caches bytecode automatically is good to know.

                  推荐答案

                  不确定 APC 是否是唯一的解决方案,但 APC 确实可以解决您的所有问题.

                  Not sure if APC is the only solution but APC does take care of all your issues.

                  首先,您的脚本将使用 APC 编译一次,并将字节码存储在内存中.

                  First, your script will be compiled once with APC and the bytecode is stored in memory.

                  如果您的设置需要很长时间,您还可以将其作为用户数据缓存在 APC 中.例如,我一直这样做,

                  If you have something taking long time to setup, you can also cache it in APC as user data. For example, I do this all the time,

                              $table = @apc_fetch(TABLE_KEY);
                  
                              if (!$table) {
                                      $table = new Table(); // Take long time
                                      apc_store(TABLE_KEY, $table);
                              }
                  

                  使用 APC,每个服务器实例只执行一次创建表的任务.

                  With APC, the task of creating table is only performed once per server instance.

                  这篇关于如何在 PHP 中的请求之间持久化对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Converting between timezones in PHP(在 PHP 中的时区之间转换)
                  PHP - strtotime, specify timezone(PHP - strtotime,指定时区)
                  Get current date, given a timezone in PHP?(获取当前日期,给定 PHP 中的时区?)
                  List of US Time Zones for PHP to use?(PHP 使用的美国时区列表?)
                  How to detect Ambiguous and Invalid DateTime in PHP?(如何在 PHP 中检测不明确和无效的 DateTime?)
                  How to update timezonedb in PHP (updating timezones info)?(如何在 PHP 中更新 timezonedb(更新时区信息)?)
                  <legend id='QMKP5'><style id='QMKP5'><dir id='QMKP5'><q id='QMKP5'></q></dir></style></legend>
                2. <small id='QMKP5'></small><noframes id='QMKP5'>

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

                              <tbody id='QMKP5'></tbody>