Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75114 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 96571 invoked from network); 27 Jun 2014 14:20:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2014 14:20:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Received-SPF: error (pb1.pair.com: domain schlueters.de from 217.114.215.10 cause and error) X-PHP-List-Original-Sender: johannes@schlueters.de X-Host-Fingerprint: 217.114.215.10 mail.experimentalworks.net Received: from [217.114.215.10] ([217.114.215.10:59907] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9E/EA-11209-CBD7DA35 for ; Fri, 27 Jun 2014 10:20:45 -0400 Received: by mail.experimentalworks.net (Postfix, from userid 1003) id B4F1C4134D; Fri, 27 Jun 2014 16:20:46 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on km31408.keymachine.de X-Spam-Level: X-Spam-Status: No, score=-1.0 required=3.0 tests=ALL_TRUSTED autolearn=ham version=3.3.2 X-Spam-HAM-Report: * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP Received: from [192.168.2.31] (ppp-93-104-15-92.dynamic.mnet-online.de [93.104.15.92]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johannes@schlueters.de) by mail.experimentalworks.net (Postfix) with ESMTPSA id AAB394134A; Fri, 27 Jun 2014 16:20:42 +0200 (CEST) To: Ingwie Phoenix Cc: internals@lists.php.net In-Reply-To: <02B340AD-6EED-497D-85EC-F5C37A7504B6@googlemail.com> References: <1403777679.12695.14.camel@guybrush> <0DF815F8-5991-46EC-9BD4-53575F774BAC@googlemail.com> <1403860716.12695.34.camel@guybrush> <02B340AD-6EED-497D-85EC-F5C37A7504B6@googlemail.com> Content-Type: text/plain; charset="UTF-8" Date: Fri, 27 Jun 2014 16:20:00 +0200 Message-ID: <1403878800.12695.58.camel@guybrush> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Embedding PHP, few additional questions. From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) On Fri, 2014-06-27 at 14:55 +0200, Ingwie Phoenix wrote: > So there is two methods of supplying headers? O.o oha. Well I will go there are request and response headers and then there are different situations the response headers might be set in ... > and check the files out and see what it helps me. Yes, looking at the code is useful to understand it. > Yes. child_process.spawn is non-blocking - it just returns an Event > Emitter and the stdin/stdout/stderr stream resources respectively. In > fact, I want to model my PHP binding in such fashion too. Currently, I > am firstly wanting to understand the API and create a good base for > the module. Then extend it to be async/non-blocking. So, I will be > replacing output and error output functions with respective callbacks. > However, I am not planning to add any functionality to create userland > functions from JS. I only want to be able to prepare a bunch of > information - the file to be executed, the in-/output methods, etc - > then give it to a function, which will create a new thread (in libuv, > uv_async_t, or soemthing) and execute the given PHP file with the > engine. The handle returned will contain the running PHP instance - or > at least, i need to find a way to run PHP and then keep it up, so that > my OPCaches wouldnt get lost. Forget Opcache. Get the PHP model of the request based approach which goes through PHP's complete architecture. opcache comes in in the end (more or less) easily. > But this brings me to another question. > > When I look into pconnect SAPI, I can see that you start PHP…but > actually, I can see no real reference to a „PHP interpreter object“. > In a third-party implementation of PHP, called PH7, one has to create > a ph7_engine_t first - which corresponds to the actual engine > instance. > > If I want to keep PHP running - and even multiple instances - how > would I do that? If I have no handle to differenciate between PHP > instances, then I have a small problem…and I would have to actually > fall back to using PHP-CGI/-FPM, which I wanted to avoid, as I was > hoping for a speed improvement if everything happened in-process/per > thread. As said before the request context is defined by request startup and shutdown functions. This works by using globals to keep the state. In threaded environments, to run multiple requests in parallel we have TSRM as thread isolation layer binding a request context to a thread. Thus the request is bound to a thread. Once it's finished it can handle the next request. My pconn SAPI supports some form of parallelism, too. check the main.c file. But for your project this becomes really messy - a "request" comes in, you start a worker thread fill it with the data. The output hooks then have to be written in a way to capture the output and send it back to the v8 thread which will, once it has time handle those and report back to the javascript code. Now if you want to make it efficient you can't create a fresh thread each time but instead want to create a worker pool of threads and some scheduler putting tasks in. Then besides that complexity you have to mind other issues in this setup. for instance TSRM mode is slower than non TSRM mode. Or as everthing is one process. A crashing PHP (stack overflow due to infinite recursion) will kill all parallel PHP requests and the whole node instance. So really if you plan on operating such a thing write a FastCGI or FPM module calling PHP in such a way. Or even better: Make your PHP code a web service (REST etc.) so both sides can be scaled individually. If you want to do this for academic purposes or proving me wrong, please read the code and try to understand it. Experiment with it in small pieces etc. johannes