Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:75115 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99839 invoked from network); 27 Jun 2014 14:53:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jun 2014 14:53:27 -0000 Authentication-Results: pb1.pair.com smtp.mail=ingwie2000@googlemail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ingwie2000@googlemail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 74.125.82.41 as permitted sender) X-PHP-List-Original-Sender: ingwie2000@googlemail.com X-Host-Fingerprint: 74.125.82.41 mail-wg0-f41.google.com Received: from [74.125.82.41] ([74.125.82.41:45884] helo=mail-wg0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C3/8B-11209-6658DA35 for ; Fri, 27 Jun 2014 10:53:27 -0400 Received: by mail-wg0-f41.google.com with SMTP id a1so5303456wgh.12 for ; Fri, 27 Jun 2014 07:53:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :message-id:references:to; bh=r9sz6FKe5RRjzyRaeL9qUhcsCbRaFcJYKmd7++7pMhQ=; b=kCv1g4GVeSijTNtZnZp8cZ/DMfNzBX0H0eoeTaXpY6wJYxupK4z6h7CsREKJgltxMv vOu5CRnAzmgrYiKoHqLmpHzvCWTdtJ07iZAZ+lo1dCbmxvtdjNq8JpLUBjJGWvAlpvc2 oifLVqvELvxQrZgfNcGah6U3ZU1bPSMq1/8BgjDLwi+HzcsTgf/WKqR/AXIbZ1DTIrrN GDXFiOhw13LcbBw8eWu8I64GFMXYmSZnjKqQZBi/qlv94bibkR3fA8RtYTl1HPMdbFwK hKnZjew+UJe+HJ75MoeyVHo0ms5hkmLjFf5yPjogSOIXzDa69LLUHND071JSOkBzmq5S g0/w== X-Received: by 10.180.221.133 with SMTP id qe5mr12388696wic.79.1403880803961; Fri, 27 Jun 2014 07:53:23 -0700 (PDT) Received: from juergenensimac6.speedport_w723_v_typ_a_1_01_001 (p5B1500CB.dip0.t-ipconnect.de. [91.21.0.203]) by mx.google.com with ESMTPSA id wz3sm21858532wjc.39.2014.06.27.07.53.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 27 Jun 2014 07:53:23 -0700 (PDT) Content-Type: multipart/alternative; boundary="Apple-Mail=_10839D48-3197-42D4-8AEC-84E6460E5E19" Mime-Version: 1.0 (Mac OS X Mail 7.3 \(1878.2\)) In-Reply-To: <1403878800.12695.58.camel@guybrush> Date: Fri, 27 Jun 2014 16:53:17 +0200 Cc: internals@lists.php.net Message-ID: <69DDB98B-1874-43BA-B6DB-B878C8E54DBF@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> <1403878800.12695.58.camel@guybrush> To: =?iso-8859-1?Q?Johannes_Schl=FCter?= X-Mailer: Apple Mail (2.1878.2) Subject: Re: [PHP-DEV] Embedding PHP, few additional questions. From: ingwie2000@googlemail.com (Ingwie Phoenix) --Apple-Mail=_10839D48-3197-42D4-8AEC-84E6460E5E19 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Am 27.06.2014 um 16:20 schrieb Johannes 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 >=20 > there are request and response headers and then there are different > situations the response headers might be set in =85 Whoah, so many options... o-o >> and check the files out and see what it helps me. >=20 > Yes, looking at the code is useful to understand it. >=20 >> 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. >=20 > 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. What do you mean by that? It might be my english, but I did not very = much understand what you ment. >> But this brings me to another question. >>=20 >> When I look into pconnect SAPI, I can see that you start PHP=85but >> actually, I can see no real reference to a =84PHP interpreter = object=93. >> 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. >>=20 >> 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=85and 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. >=20 > 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. Actually, I am indeed scrolling thru pconn. It currently has the most = clean API showcase that I can see, to be very honest. But now, you = actually finally helped me understand soemthing that I always wondered: = the TSRM_xx macros! Now it makes sense why they are everywhere, acting = as a sort-of mutex=85or more, a thing to differenciate between threads. = Always got confused about how this actually is used - well, now I know. = A lesson a day, keeps the dumbness away, methinks! ^.^ > 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. >=20 > 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. Oh s=85 That I did not know/consider. So if, for some reason, the PHP = instance crashes or dies, all other instances, and possibly the rest of = the application, dies too? Wow. Guess I should create a watchdog that = keeps track of the service. > 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. The goal is to run websockets, a cdn and db cache together with HTTP(S). = So turning into REST based service would actually make the structure = more complex. Actually, I can show you the concept documentation. It is = still in progress, but it lists quite a lot of the concepts, ideas and = things I will/want to do. Maybe it helps why I am even doing this. [1] > 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. >=20 > johannes I am reading all the code that I can now, that is related to what I am = doing. I just noticed that the PHP on OS X has no maintainer-zts. So, I = am compiling 5.5.14 with embed and maintainer-zts meanwhile=85 Thanks for all your help, it really brings me forward a lot! Kind regards, Ingwie. [1]: https://gist.github.com/IngwiePhoenix/e32757a2983213fcc050 [2]: https://github.com/IngwiePhoenix/v8php The repo where I will put my = stuff=85very rough layout, not usable. Just there to be there.= --Apple-Mail=_10839D48-3197-42D4-8AEC-84E6460E5E19--