Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80909 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 97015 invoked from network); 20 Jan 2015 22:11:55 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 22:11:55 -0000 Authentication-Results: pb1.pair.com header.from=johannes@schlueters.de; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=johannes@schlueters.de; spf=permerror; 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:37639] helo=mail.experimentalworks.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 78/99-49046-8A2DEB45 for ; Tue, 20 Jan 2015 17:11:53 -0500 Received: by mail.experimentalworks.net (Postfix, from userid 1003) id 2448D48767; Tue, 20 Jan 2015 23:12:17 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on km31408.keymachine.de X-Spam-Level: * X-Spam-Status: No, score=1.4 required=3.0 tests=ALL_TRUSTED, DNS_FROM_AHBL_RHSBL autolearn=no version=3.3.2 X-Spam-HAM-Report: * 2.4 DNS_FROM_AHBL_RHSBL RBL: Envelope sender listed in dnsbl.ahbl.org * -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP Received: from [192.168.2.34] (ppp-93-104-12-121.dynamic.mnet-online.de [93.104.12.121]) (using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: johannes@schlueters.de) by mail.experimentalworks.net (Postfix) with ESMTPSA id 16EB448767; Tue, 20 Jan 2015 23:12:15 +0100 (CET) Message-ID: <1421791904.5725.38.camel@kuechenschabe> To: "Kevin Ingwersen (Ingwie Phoenix)" Cc: PHP Internals Date: Tue, 20 Jan 2015 23:11:44 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Casting a PHP type, new SAPI From: johannes@schlueters.de (Johannes =?ISO-8859-1?Q?Schl=FCter?=) Hi, 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 > 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, ... Anyways: > 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? What does that mean? Object in PHP-sense or in C-sense or C++-sense or JSON? They are all different things. 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. 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. If you want the equivalent of $obj = (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. 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) Unless you have precise questions it's hard to answer expect pointing out default resources (PHP source, Sara's book, phpinternalsbook.com, ...) > I’d 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++. 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). Using threads means pain with PHP. One thing is TSRM (while replaced in PHP 7 with TLS) 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.) 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) 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. johannes