Page 1 of 1

php networking

Posted: Fri Jul 05, 2002 2:59 am
by saryon
I created a little server toy in PHP, using the few examples i could
find on the net. But i seem to have run into a little problem.
Every time i connect, everything goes fine.
When i connect a second time (without disconnecting the first), i have to
first close the first connection before the second connection does anything
at all.
Does anyone know how i can get PHP to create a multi-connection server,
instead of a single-connection one?

Sar

Posted: Fri Jul 05, 2002 7:40 am
by llimllib
hmmm...that's an interesting problem...since you can't create threads (to my knowledge) in PHP manually, and you wouldn't want to fork the process even if you could, I can't see how you would solve this except by writing a C extension to PHP. While doable, it certainly would not be easy - although, hopefully, there's a workaround I haven't considered.

Posted: Fri Jul 05, 2002 8:00 am
by saryon
I'm not sure that threading is necessary, because there are various c-programs which aren't
threaded, yet can still handle multiple connections by going through the list of sockets in a
round-robin style (like muds do).
But this would require the ability to have multiple connections to the same socket, and that
seems to be something that is hard to do in PHP.

Posted: Fri Jul 05, 2002 8:06 am
by llimllib
do you have any code for that behavior? I'd love to see it; what socket library does it use?

File sharing?

Posted: Fri Jul 05, 2002 8:18 am
by ame12
Are you trying to do something like P2P file sharing? The free BadBlue web server does all of this for you - plus run PHP scripts. It supports the Gnutella protocol in either private or public networks.

So you could, in theory, run a PHP script that searches an entire Gnutella network for a specific file and then download it. The PHP ShareOffice library ( http://badblue.com/helpphpo.htm ) is probably a good place to start, since it calls into the server for purposes of returning Excel or Access data. You could modify some of the PHP scripts to instead execute a P2P search on network.

multi connection socket works !!!!!!!!!!!!!!!!!!!!!!!!!! :)

Posted: Fri Jul 05, 2002 9:41 am
by saryon
woohooo :D :) :D :) :D
ok, i have it so far that it actually accepts multiple connections.
I did this by using socket_select, and going through the list of sockets.
the only problem is now, that connection #2 needs to send data, so that
connection 1 can send data again.
This kinda sucks, but i'm trying to figure out how to fix that problem.....

pseudocode:

Code: Select all

<socket setting up>
for($i = 0 ; $i < max_sockets ; $i++)
     clientlist&#1111;$i]
do
&#123;
        socketlist&#1111;0] = listensocket
        set all clientsockets in socketlist
        nready = socket_select($listensocket, null, null, 0 0)
        if(inarray(lsitensocket, socketlist)
        &#123;
               loop through socketlist
               &#123;
                           if(client isn't a resource)
                                        create new socket
                           else
                                         send/receive data
               &#125;
        &#125;
&#125; while(true)

Re: File sharing?

Posted: Fri Jul 05, 2002 9:53 am
by saryon
ame12 wrote:Are you trying to do something like P2P file sharing? The free BadBlue web server does all of this for you - plus run PHP scripts. It supports the Gnutella protocol in either private or public networks.

So you could, in theory, run a PHP script that searches an entire Gnutella network for a specific file and then download it. The PHP ShareOffice library ( http://badblue.com/helpphpo.htm ) is probably a good place to start, since it calls into the server for purposes of returning Excel or Access data. You could modify some of the PHP scripts to instead execute a P2P search on network.

what i am trying to do is set up a simple server, which allows people to connect to, chat or
something, and then disconnect.
i have no real intention to make it some kind of fileswapping thing, because there are already
about 9279471947366149400 different clients out there, which do the same thing, and
besides i'm too lazy to actually go into that code and try to figure out how the
clients talk to eachother ;)
It's mostly a toy, trying to figure out how i can get sockets to really work nicely with php,
and maybe, some day, i'll make something more interesting out of it.
a webserver/chatserver/mailserver/whatever.

Posted: Fri Jul 05, 2002 10:45 am
by llimllib
congrats sary, good job

Good job

Posted: Sat Jul 06, 2002 7:37 am
by ame12
Yes, good job on the socket code - that's interesting stuff.

Regarding writing a web server, etc. - the only caution is on the security side, there's a fair amount of security stuff (URL filtering) that a server has to do to ensure that users aren't opening up "gaping security holes" on their PCs. So be careful if you do end up writing that for real usage...

Re: Good job

Posted: Mon Jul 08, 2002 1:44 am
by saryon
ame12 wrote:Yes, good job on the socket code - that's interesting stuff.

Regarding writing a web server, etc. - the only caution is on the security side, there's a fair amount of security stuff (URL filtering) that a server has to do to ensure that users aren't opening up "gaping security holes" on their PCs. So be careful if you do end up writing that for real usage...
thanks :)


but......real usage? *rofl* right....
first i want it to actually try and do something ;)
whatever happens then....and whatever i make of it...we'll see.