Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59383 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37596 invoked from network); 6 Apr 2012 23:45:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 6 Apr 2012 23:45:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=luke@cywh.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=luke@cywh.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain cywh.com from 209.85.210.45 cause and error) X-PHP-List-Original-Sender: luke@cywh.com X-Host-Fingerprint: 209.85.210.45 mail-pz0-f45.google.com Received: from [209.85.210.45] ([209.85.210.45:56282] helo=mail-pz0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 60/FD-57786-8008F7F4 for ; Fri, 06 Apr 2012 19:45:13 -0400 Received: by dacx6 with SMTP id x6so3363135dac.18 for ; Fri, 06 Apr 2012 16:45:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=user-agent:date:subject:from:to:message-id:thread-topic :mime-version:content-type:x-gm-message-state; bh=MxioOj3bfStFFybDWwfJYkrCL+tAMTM97KjnhVND20A=; b=FJYPMPWXOrSDdlS4YKIoKBsVcAUIxlIXKCPeonE5Oo/CCcaKjoNCILsRwXneqt1P58 3T7M36170GU8fMjk2r5Wf1hEruzxegQEgdvn4KGl9/W124zGw8089jPttLkbpR6z9liS gtRqJJfT9SVkX6fguk7qZRzqV/fJhde2uWfpzq72AyxuyBXU4UZ2NtvG0UuNoA77vitD 1Jvw1QeQfxQc0gMOz9LuObIK1pMmH0Y+2hbqntNl3RCTd63ZKe80E+52UK27Qr5q7je/ 7FP9db4dnni3J671yzchU1k5xZoG72P7Dsks940af0S/hvq/XF/r3HAXGaLk8Yjfhdgr 2AYw== Received: by 10.68.195.232 with SMTP id ih8mr620946pbc.118.1333755910286; Fri, 06 Apr 2012 16:45:10 -0700 (PDT) Received: from [10.1.10.222] ([66.60.139.106]) by mx.google.com with ESMTPS id o7sm7531645pbq.8.2012.04.06.16.45.09 (version=SSLv3 cipher=OTHER); Fri, 06 Apr 2012 16:45:09 -0700 (PDT) User-Agent: Microsoft-MacOutlook/14.13.0.110805 Date: Fri, 06 Apr 2012 16:46:44 -0700 To: Message-ID: Thread-Topic: Persistent zvals Mime-version: 1.0 Content-type: multipart/alternative; boundary="B_3416575607_42878551" X-Gm-Message-State: ALoCoQnpdi0UFf6z6KPQZPMeT0uxUiJkK4b/28qNwp36cZz2dVrSF9ms8wX5GppA3EZsU7ryMMn/ Subject: Persistent zvals From: luke@cywh.com (Luke Scott) --B_3416575607_42878551 Content-type: text/plain; charset="ISO-8859-1" Content-transfer-encoding: quoted-printable I've spent the last few days pouring over the Zend engine source code. I think I have a basic understanding on the memory management. Likely what I say may be incorrect, so I apologize in advance. What I'm trying to do is write an extension to persist PHP variables past the end of the request in the SAPI to be used on the next request (differen= t user, same process). I'd like to do this without serialization. The reason is certain objects in PHP (in a framework, for example) are not request specific and it would be useful to have these objects already loaded and usable without having to construct them on every request. (Sample use case: Dependency injection like Guice without having to write physical containers - using reflection, written in PHP) From what I've gathered thus far, it is impossible to do without copying th= e non-persistent memory into persistent memory, and then back again. I'm assuming this is because all the memory associated with PHP variables use emalloc, which places it onto a stack that is disposed of at the end of the request. So there seems to only be two ways to do this: 1 - Copy non-persistent memory into persistent memory (and back) using a deep copy. Probably not very efficient. May not be much better than serialization. 2 - Modify the Zend engine to flag objects/zvals as persistent so they aren=B9t thrown away until the process ends. #2 seems to be the better way to go. #1 seems to be the only way to do it a= s an extension (maintaining its own stack). There seems to have been some discussion (7 years ago) of this mentioned here under 6.9: http://www.php.net/~derick/meeting-notes.html I've been able to do it somewhat with string zvals, but objects are a different story (given that a zval contains a handle index referring an entry in a bucket). The "goal", at least with objects, is the objects doesn't destruct until the end of the process. With copying memory it looks like I'd probably have to copy the object into my own bucket, modify the original in zend's bucket so the destructor isn't called (destructor_callle= d =3D 1), and then at the start of the request copy what's in my bucket into zend's bucket. At this point I feel light a mad scientist. I'm hoping to gain some insight on how this might be done properly with PHP 5.3/5.4 (or just 5.4) - even if it involves modifying the Zend engine. Have you guys had any recent discussions about doing this? Luke --B_3416575607_42878551--