Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>PHP has an execution model where each web request from the host environment generates a new, fresh PHP environment which is destroyed when the request is completed.</p> <p>So the simple answer is no, you cannot create an object and persist it between requests. You must "persist" the object in some other way:</p> <ol> <li>Through serialization/deserialization, using sessions, a database, a key-value store like APC, a file on the file system, or some other method.</li> <li>By having a separate long-running process hold the object, and having PHP objects communicate with it via some IPC method, such as shared memory, pipes, sockets, etc.</li> </ol> <p>I don't know much about COM, but since COM objects can be created outside the running process I suspect that there is probably some (not-PHP specific) method of connecting to an existing one rather than creating a new one. (This is essentially option 2 above, using the COM services as the IPC.)</p> <p>A little digging through the PHP COM library docs reveals the <a href="http://www.php.net/manual/en/function.com-get-active-object.php" rel="nofollow"><code>com_get_active_object()</code></a> function, which may bring you to a working solution. However, you will probably need to learn more about COM from non-PHP sources. Also, <strong>read the big fat warning about using a single COM object concurrently</strong>:</p> <blockquote> <p>Using <code>com_get_active_object()</code> in a web server context is not always a smart idea. Most COM/OLE applications are not designed to handle more than one client concurrently, even (or especially!) Microsoft Office. You should read <a href="http://support.microsoft.com/kb/257757" rel="nofollow">» Considerations for Server-Side Automation of Office</a> for more information on the general issues involved.</p> </blockquote> <p>This suggests to me that creating a singleton COM object shared among all requests is actually what you <em>don't</em> want to do!</p> <p>If that doesn't work, PHP has an <a href="http://php.net/manual/en/language.oop5.serialization.php" rel="nofollow">object serialization method</a> that allows you to serialize the running state of an object to a string and deserialize it back again to the same state. You can customize this by adding the <a href="http://php.net/manual/en/oop4.magic-functions.php" rel="nofollow"><code>__sleep()</code> and <code>__wakeup()</code></a> methods to your class. This mechanism has it's share of quirks and I don't know how well the PHP COM library proxy objects would support it.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload