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 > <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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php