Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:59393 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81445 invoked from network); 7 Apr 2012 11:59:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Apr 2012 11:59:16 -0000 Authentication-Results: pb1.pair.com header.from=tom@punkave.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tom@punkave.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain punkave.com designates 209.85.216.49 as permitted sender) X-PHP-List-Original-Sender: tom@punkave.com X-Host-Fingerprint: 209.85.216.49 mail-qa0-f49.google.com Received: from [209.85.216.49] ([209.85.216.49:37975] helo=mail-qa0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F5/A4-57786-31C208F4 for ; Sat, 07 Apr 2012 07:59:16 -0400 Received: by qafi29 with SMTP id i29so871531qaf.8 for ; Sat, 07 Apr 2012 04:59:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=references:in-reply-to:mime-version:content-transfer-encoding :content-type:message-id:cc:x-mailer:from:subject:date:to :x-gm-message-state; bh=KKjbGlP1/9XtvDLfUvOOgbR3agGBthFe9OAgAci7Pe4=; b=ZvUf/4vfJXxLPMUqdIeTAKChr8UBa4gGhKo4+6vuETH+8yvfQwmhSM9jv4N8vBMdoc jUS8J9EOjWPl82jNGzJ6rnhpQQvBOwM5eLY9hJPX4q9/vxqYPk1gy8IXXjIk89YBaNGU o3d9cfCOXQNoqOuFzqgp7C8a4utG0MlPzwfOMlcDsc1dGhxwcr7tgj56z9lX0QRbyOgt R9nA/te2tPtYoKazLf04uMntLI1GFe7GBO2ywnEZgyUlRFyvSl1XBc7LSPGXB9qU20pk dcWTTyPUmAuT6m1PxAzGpulurlmAaLt00PBb31A84d+24ncsbTiAelo/Yy7zEf3IpY4X bLng== Received: by 10.224.204.131 with SMTP id fm3mr1489514qab.27.1333799953371; Sat, 07 Apr 2012 04:59:13 -0700 (PDT) Received: from [192.168.100.101] (c-68-81-107-211.hsd1.pa.comcast.net. [68.81.107.211]) by mx.google.com with ESMTPS id gg5sm10382072qab.7.2012.04.07.04.59.12 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 07 Apr 2012 04:59:12 -0700 (PDT) References: In-Reply-To: Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Message-ID: <6F308292-58F2-4C0C-A001-DBAB1E620308@punkave.com> Cc: "" X-Mailer: iPhone Mail (9B176) Date: Sat, 7 Apr 2012 07:59:09 -0400 To: Luke Scott X-Gm-Message-State: ALoCoQkotxUt+E0zA1/itPYBGWE8425bLh4/CdP7Dz5hmrqZOZBHfFJtzDLrH2ckcKLu26EA1vJc Subject: Re: [PHP-DEV] Persistent zvals From: tom@punkave.com (Tom Boutell) Indeed phpdaemon.net appears to cover this ground, although your idea might d= eliver higher performance. Sent from my iPhone On Apr 6, 2012, at 7:46 PM, Luke Scott wrote: > 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. >=20 > 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 (differe= nt > 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 container= s > - using reflection, written in PHP) >=20 > =46rom what I've gathered thus far, it is impossible to do without copying= the > 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 th= e > request. >=20 > So there seems to only be two ways to do this: >=20 > 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. >=20 > 2 - Modify the Zend engine to flag objects/zvals as persistent so they > aren=C2=B9t thrown away until the process ends. >=20 > #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). >=20 > There seems to have been some discussion (7 years ago) of this mentioned > here under 6.9: >=20 > http://www.php.net/~derick/meeting-notes.html >=20 > 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 look= s > 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_calll= ed > =3D 1), and then at the start of the request copy what's in my bucket into= > zend's bucket. >=20 > At this point I feel light a mad scientist. I'm hoping to gain some insigh= t > on how this might be done properly with PHP 5.3/5.4 (or just 5.4) - even i= f > it involves modifying the Zend engine. Have you guys had any recent > discussions about doing this? >=20 > Luke >=20 >=20 >=20