PHP Socket Programming, done the Right Way
christophh.net
PHP Socket Programming, done the Right Way
1–10 of 15 posts
Re: PHP Socket Programming, done the Right Way
#2Re: PHP Socket Programming, done the Right Way
#3How are there no comments? This is the most hilarious blog post title I've seen in ages!
Re: PHP Socket Programming, done the Right Way
#4Re: PHP Socket Programming, done the Right Way
#5Re: PHP Socket Programming, done the Right Way
#6Or at least use namespaces. There is no reason to stick with the native PHP wrappers. It's common knowledge that PHP function names are illogical because of backward compatibility. So why not use a wrapper?
I think it's sad that even after PHP got all these features so that it resembles a proper programming languages, people aren't even using them! Makes me wonder if it was a good decision to force people to use classes in Java...
Re: PHP Socket Programming, done the Right Way
#7Let's say I want to build some sort of notification service. This could be instant messages, presence indication, or notification of file changes ala dropbox.
Now let's say that most of my clients are behind firewalls, forcing me to tie up one of my ports for each client as I do long polling or something else to keep the connection through their NAT open.
How do you keep from running out of ports? I only have 65K ports, right? How do some of these companies that have millions of open connections do it?
Re: PHP Socket Programming, done the Right Way
#8I have a question regarding socket programming in general. Let's say I want to build some sort of notification service. This could be instant messages, presence indication, or notification of file changes ala dropbox. Now let's say that most of my clients are behind firewalls, forcing me to tie up one of my ports for each client as I do long polling or something else to keep the connection through their NAT open. How…
You can have 65535 connections (in theory) from a single client to your port 80. And another 65535 from a different client to port 80 on the same server.
If you're serving a bunch of different clients it's not a problem.
Re: PHP Socket Programming, done the Right Way
#9Why not use a class? http://pear.php.net/package/Net_Socket Or at least use namespaces. There is no reason to stick with the native PHP wrappers. It's common knowledge that PHP function names are illogical because of backward compatibility. So why not use a wrapper? I think it's sad that even after PHP got all these features so that it resembles a proper programming languages, people aren't even using them! Makes me…
Classes being a good abstraction:
$user = new User('John', 'Doe');
$user->authenticate($token);
Classes being a bad abstraction: $two = Math::add(1, 1);
// or worse:
$math = new Math;
$three = $math->sqrt(9);
In that latter case, you'd be much better served using a functional or procedural API, even if it's namespaced: (+ 1 1) ; two
(math/sqrt 9) ; three
If you're going to argue that `stream_socket_` is doing it wrong, I'd like to hear why it'd be better as a OO API.Re: PHP Socket Programming, done the Right Way
#10Code here looks good on first look tho.