AliceWonder32 Posted October 13, 2012 Share Posted October 13, 2012 Working on a web application involving server sent events. Apache is not good for this because of the persistent connections. node.js is awesome for this - but it's Javascript. I like postgresql (which I prefer to interface with via PDO), I like php, I like to keep the server side of things all in one language if I can. I've found node.js interface to MySQL but it really looks like node.js database layers are bolt on and not that mature yet. Is there a good web server for maintaining lots of connections that runs php? Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/ Share on other sites More sharing options...
ignace Posted October 13, 2012 Share Posted October 13, 2012 (edited) Apache is not good for this because of the persistent connections. 1) Why is that bad? 2) Why not simply send Connection: close upon each request instead of telling it to persist? 3) Would nginx be an option? It uses FastCGI? Edited October 13, 2012 by ignace Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1385020 Share on other sites More sharing options...
AliceWonder32 Posted October 13, 2012 Author Share Posted October 13, 2012 Apache runs out of threads. It just can not maintain that many simultaneous connections. The point of Server Sent Events is that the web server can send messages to the browser without the browser needing to request them. If the connection is broken, the browser re-connects with the ID of last message it received so that it can get any messages it missed. It allows web applications that need server push capabilities to work without using flash or java - and without frequent polling that can be very hard on the server. I don't know if nginx is an option or not, I've not used it. Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1385025 Share on other sites More sharing options...
Christian F. Posted October 13, 2012 Share Posted October 13, 2012 If you want to make a socket server in PHP, then I think you'll find everything you need in the PHP manual. It's quite simple to make a socket server in PHP after all. That said, if your Apache install is running out of threads you're either configured it wrong, written some bad code, or you have a huge number of unique visitors. I suspect that the first two scenarios are the most likely ones. Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1385026 Share on other sites More sharing options...
trq Posted October 14, 2012 Share Posted October 14, 2012 node.js is awesome for this - but it's Javascript. I'm not sure I see the point here. Javascript is an awesome language that should be known by all web developers IMO. node.js database layers are bolt on and not that mature yet. Just like PHP, everything in node is an extension library, and yeah, a lot of this stuff is pretty new. Node.js is however advancing really quickly and there are a lot of real smart dudes working on / with it. Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1385053 Share on other sites More sharing options...
AliceWonder32 Posted October 14, 2012 Author Share Posted October 14, 2012 The point is that by using the same language for all things in the web app, code can be shared. For example, the class for session handling (I keep session info in a database), database connection, etc. so that future maintenance of the web application does not require changes to the php side of things and then the Javascript port of the php side of things. You can update a single class that both the main web app and the server side EventSource page. Of course the web developer needs to know Javascript for the client side programming, but the client side programming doesn't interface with server resources directly, it sends those as requests to the web application. If I have to do that part of the web app in node.js I'll do it in node.js but I would prefer to do it in php because the rest of the web app (a social network platform) is php. What I'm trying to do is leverage the power of html5 to remove all use of plugins. I hate browser plugins with a passion. Probably from my days running ppc linux where there were none so any site that required them was broken, but hell, I even hate dependence upon them in Windows. To keep everything server side php is why I'm seeking a php capable http server that does not have the same persistent connection limitations of Apache. Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1385100 Share on other sites More sharing options...
kicken Posted October 14, 2012 Share Posted October 14, 2012 What you would end up doing with PHP is create your server socket and then use non-blocking IO + stream_select to handle all the incoming connections. You could manage quite a few connections that way in just a single thread/process. Throwing pcntl_fork into the mix may allow even more connections to be handled. https://aoeex.com/chat/phpchatd.phps is a example I made a while back that uses the principal above. It acts as a simple server that handles all the long-poll connections for a AJAX chat room. The demo chat room that uses it is at https://aoeex.com/chat/chat.html. Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1385105 Share on other sites More sharing options...
AliceWonder32 Posted October 14, 2012 Author Share Posted October 14, 2012 Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1385170 Share on other sites More sharing options...
Mahngiel Posted October 14, 2012 Share Posted October 14, 2012 (edited) This posts reminds me of Edited October 14, 2012 by Mahngiel Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1385174 Share on other sites More sharing options...
AliceWonder32 Posted October 15, 2012 Author Share Posted October 15, 2012 That was awesome! Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1385218 Share on other sites More sharing options...
AliceWonder32 Posted October 22, 2012 Author Share Posted October 22, 2012 I now have a CLI php based socket server doing much of what I want (rest is matter of finishing my code), thank you kicken for the suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1386866 Share on other sites More sharing options...
Andy-H Posted December 29, 2012 Share Posted December 29, 2012 https://github.com/reactphp/react Written by @igorwesome, although personally, I'd just use NodeJS Quote Link to comment https://forums.phpfreaks.com/topic/269429-php-equivalent-for-nodejs/#findComment-1402058 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.