Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81026 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57013 invoked from network); 23 Jan 2015 06:38:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 23 Jan 2015 06:38:37 -0000 Authentication-Results: pb1.pair.com header.from=ingwie2000@googlemail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ingwie2000@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 74.125.82.171 as permitted sender) X-PHP-List-Original-Sender: ingwie2000@googlemail.com X-Host-Fingerprint: 74.125.82.171 mail-we0-f171.google.com Received: from [74.125.82.171] ([74.125.82.171:36342] helo=mail-we0-f171.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D8/E2-61273-A6CE1C45 for ; Fri, 23 Jan 2015 01:38:35 -0500 Received: by mail-we0-f171.google.com with SMTP id q58so5781828wes.2 for ; Thu, 22 Jan 2015 22:38:30 -0800 (PST) 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 :content-transfer-encoding:message-id:references:to; bh=noW5FIlDdZ8bfTV5oLnHH3hMcehMH1Ts9T31mGWi96I=; b=oFwZIz3iu96Wb6CWbhZYbjR49sRjtEgxL5vTRwLYMjmUlq8N1QY/JCXeDvOSQ1dTNc N/voHtPFfcJL3J4NTa9AWoIf47F2TErhDV2PvhEQow1wwU55yGcChcdhXgDLg0Stt21Z /OiKdxKLT31Psz7QnOyvZD3bHxHZAZgasiVfUVt3MvkFHjy1NXQnEdaBFrPO+now//lm mAaWVG7e4BMLS9BWZK3yPPaKPu81ufgRYpelLvoJr3hGmqYHYXohOC/w5tzOY4EbMS4J HmsfR7geG5xYRFgNW76bup8FY6sv9tvIEKE6yPY3rF3fWI9bN2djcUWk8h4JU/XaG48m pfwg== X-Received: by 10.194.203.104 with SMTP id kp8mr10359487wjc.103.1421995110718; Thu, 22 Jan 2015 22:38:30 -0800 (PST) Received: from [192.168.200.47] (dslb-188-097-120-097.188.097.pools.vodafone-ip.de. [188.97.120.97]) by mx.google.com with ESMTPSA id a14sm462233wib.22.2015.01.22.22.38.29 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 22 Jan 2015 22:38:29 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.1 \(1993\)) In-Reply-To: <1421791904.5725.38.camel@kuechenschabe> Date: Fri, 23 Jan 2015 07:38:27 +0100 Cc: PHP Internals Content-Transfer-Encoding: quoted-printable Message-ID: <127445D1-DE70-4A47-976E-05EC9D3489A1@googlemail.com> References: <1421791904.5725.38.camel@kuechenschabe> To: =?utf-8?Q?Johannes_Schl=C3=BCter?= X-Mailer: Apple Mail (2.1993) Subject: Re: [PHP-DEV] Casting a PHP type, new SAPI From: ingwie2000@googlemail.com ("Kevin Ingwersen (Ingwie Phoenix)") > Am 20.01.2015 um 23:11 schrieb Johannes Schl=C3=BCter = : >=20 > Hi, >=20 > On Tue, 2015-01-20 at 06:36 +0100, Kevin Ingwersen (Ingwie Phoenix) > wrote: >> Today I have started to concept a new SAPI which I have wanted to do >> in quite a while now. To learn more, here is a README: >> https://github.com/IngwiePhoenix/php-jrp/blob/master/README.md >> >=20 > I have to agree with Bas van Beek that I don't see the benefit of = using > a custom protocol over existing ones. This protocol doesn't seem to = have > less overhead than HTTP and you loose ability of using established > libraries, debugging tools, scaling tools, ...=20 =E2=80=A6but you gain the headache of FastCGI. I just wasted 3 hours, = trying to get this working right. It was more of an issue with the = script language I am using to write the web server - but getting my head = around FastCGI in the first place is a mess. When was it written and = published, 1996? > Anyways: >=20 >> But in order for me to work this out as good as I can - especially = the >> PHP API at the bottom - I need to know just a thing I could not find >> within the public PHP headers: When I have an Array, now can I turn >> that into an object? >=20 > What does that mean? Object in PHP-sense or in C-sense or C++-sense or > JSON? They are all different things. Oh damn. I should ahve been more clear there. I was reffering to a PHP = object. > PHP arrays essentially are a zval with a HashTable, which can be used > via zend_hash.h API, there also exist some array_* shortcuts in > zend_API.h, this changes a bit between PHP 5 and 7 so you should pick > the version. >=20 > If you want a PHP object you use the object APIs, I tend take ideas = from > the reflection's implementation as it does most object things. >=20 > If you want the equivalent of $obj =3D (object)$array; I question = whether > that makes sense (you want to write json output in the end, no? so why > do an relative expensive transformation instead of directly creating > json?) but convert_to_object() in zend_operators.c is your friend. >=20 > You want to create a JSON object? Look at the json extension, which > doesn't have an API but is trivial to copy. (mind the license of the > utf8 decoder, if needed) >=20 > Unless you have precise questions it's hard to answer expect pointing > out default resources (PHP source, Sara's book, > phpinternalsbook.com, =E2=80=A6) Since there is no =E2=80=9Eobject syntax=E2=80=9C in PHP as there is in = JavaScript for instance, I can=E2=80=99t pass an actual object and need = to hack my way around and use an associative array instead. Because = there is a difference in doing $obj =3D new stdClasS; $obj->propA=3D=E2=80=A6; $obj->propB=3D=E2=80=A6; func($obj); And func([propA=3D>..., propB=3D>...]); // my Mail program mis-fixes quotes, = so I left them out And in the end, all I need is to iterate over each key - at which I = realized, I dont even need to convert it into an Object at all and can = use the existing HashTable API=E2=80=A6 My failure on that. >> I=E2=80=99d be happy to hear what you think of this concept as well. = As >> mentioned in the README, process on this will begin later. For now, I >> am going to use helper libraries, but late ron I want to strip the >> project to lesser and lesser dependencies. But it will remain being >> written in C++. >=20 > One thing I noticed is that you have a dependency on some thread > libraries (while I wonder why C++08 libraries instead of C++11's = thread > support). Mostly because the C++11 support across compilers is very wobbly. = TinyThread++ has the C++11 API mirrored, so it can be replaced by the = STL threads on a newer compiler. But for anything that doesnt support = the C++11 threads correctly, this library can do. > Using threads means pain with PHP. One thing is TSRM (while > replaced in PHP 7 with TLS)[...] I thought TSRM was stable? > [...]the other thing is stability: A crash in one > thread will crash the whole server, in a process-based model like > FastCGI or apache mod_prefork only the single process and request will > die. Crashing PHP is trivial (infinite recursion etc.) My idea was to use a thread per process watchdog. So a request is = started, and it is given to a new thread - so it has its own PHP process = running and when that one dies, it can send back an error message = accordingly. PHP was not ment to run in the same process in the first = place. > I also see PHP-CPP in your dependencies, that is nice but for writing > extensions, not SAPIs. And last time it checked it didn't really do = good > under TSRM (haven't checked for some time) It is fine with TSRM, actually. I only want to use it to simplify the = built-in extension that allows custom messages to be sent back to the = client (the instance that issued the request). > My example I use to answer SAPI questions is > https://github.com/johannes/pconn-sapi which is probably the most = simple > SAPI available, working both in threaded and non-threaded mode. Where else do you think I am getting all the SAPI docs I need in a = cheat-sheet form? :) To clarify: I mainly want to replace FastCGI. Its a pain to work with = and I am spending more time on getting a proper FastCGI connection going = than writing on my site. There is a good reason that programs like = NodeJS allow webservers to be scripted; t make things very custom and = dynamic. But since PHP=E2=80=99s only output seems to be FastCGI, the = CLI - which doesn=E2=80=99t, obviously, support the header stuff - or = probably something i have overlooked, I will need to write my own=E2=80=A6= pcntl_fork() is not in the standart PHP it seems, otherwise I would have = written JRP using that. But since this is going to be a general-purpose = SAPI anyway, I can just write it in C++ from the get-go. Kind regards, Ingwie=