Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:55808 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52964 invoked from network); 15 Oct 2011 13:02:42 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Oct 2011 13:02:42 -0000 Authentication-Results: pb1.pair.com header.from=olivier@phppro.fr; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=olivier@phppro.fr; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain phppro.fr from 74.125.82.54 cause and error) X-PHP-List-Original-Sender: olivier@phppro.fr X-Host-Fingerprint: 74.125.82.54 mail-ww0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:47832] helo=mail-ww0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E1/E2-27030-174899E4 for ; Sat, 15 Oct 2011 09:02:41 -0400 Received: by wwe5 with SMTP id 5so237615wwe.11 for ; Sat, 15 Oct 2011 06:02:38 -0700 (PDT) Received: by 10.227.200.20 with SMTP id eu20mr4399040wbb.42.1318683758315; Sat, 15 Oct 2011 06:02:38 -0700 (PDT) Received: from [10.0.1.2] (tal33-3-82-233-80-11.fbx.proxad.net. [82.233.80.11]) by mx.google.com with ESMTPS id j18sm19822450wbo.6.2011.10.15.06.02.36 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 15 Oct 2011 06:02:37 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1244.3) Content-Type: text/plain; charset=iso-8859-1 In-Reply-To: <1318634669.2966.27.camel@guybrush> Date: Sat, 15 Oct 2011 15:02:38 +0200 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: <7E0D65BB-A4EB-4A08-9037-FE3A162E89D7@phppro.fr> References: <0FE70DAD-7CF9-4EE7-B52D-736CC93876B9@phppro.fr> <1318634669.2966.27.camel@guybrush> To: =?iso-8859-1?Q?Johannes_Schl=FCter?= X-Mailer: Apple Mail (2.1244.3) Subject: Re: [PHP-DEV] Problem with PHP as a plugin (C++) using embed sapi From: olivier@phppro.fr (Olivier Hoareau) Hi Johannes, Many thanks ! I think SAPI approach is a good one for my purpose, I can then avoid = using directly the PHP/embed global variables and use functions (i.e. = the stable api you mention) to manipulate these structures. I need to = create new SAPI and compile libphp5.so including this SAPI, if I = understood well. I read recently about the "load CX before B" solution, but I think it is = not the way I want to do it (requiring the Loader to know about PHP's = function =3D> strong coupling) because PHP is only one plugin (I will = have Python and others as well), and I want a more generic solution. It is also possible to compile using shared but dynamic linking (and not = dynamic loading) CX over B (or static), requiring me to provide many B = versions (I plan to have 5.1 to 5.4 PHP support, if possible, with = multiple minor versions). I really like the SAPI approach, and probably give it a try in few days. Thanks again ! Olivier H. Le 15 oct. 2011 =E0 01:24, Johannes Schl=FCter a =E9crit : > Hi, >=20 > On Fri, 2011-10-14 at 10:49 +0200, Olivier Hoareau wrote: >> * My use case : >>=20 >> [A] is a main program written in C++ >> [B] is a C++ "plugin" of [A], compiled in a shared library = dynamically loaded (dlopen-like functions) >> [CX] are a libphpX.so C shared libraries compiled with = "--enable-embed", where "X" is the PHP version number (5.4, 5.3, ..., = 5.0) >=20 >> Do you have an idea on how to reach my use case ? >=20 > The simple answer is: You can't do this this way and you have to = provide > a [B] for each version of PHP linking [CX]. >=20 > If you really really really want to do this I see two ways, where the > first is close to what you are doing but still evil: >=20 > The approach is to add a Loader library which is loaded by [A] and = then > first loads [CX] and then the current [B]. This is evil as PHP does = not > guarantee API/ABI to stay the same over minor versions. So some random > function in libphp, which your [B] might be using, can change the > signature which will easily lead to hard to debug crashes of your > application. >=20 > The better approach is to create your own SAPI which exports a for = your > purpose stable API which you then can load. Building a SAPI is not > really hard. > https://github.com/johannes/pconn-sapi/blob/master/pconnect-sapi.c is > probably one of the most simple SAPIs, there I'm basically exporting > three more abstracted functions: pconn_init_php(), = pconn_shutdown_php() > and pconn_do_request() which in your case would form your stable API = for > your new SAPI. (mind that my pconn_do_request() includes a TSRM > parameter, in case you don't need threaded execution, can be dropped, > else you probably have to abstracted it away (make it void* and export > clean APIs to keep thread context), too) >=20 > johannes >=20 >=20