php networking
Moderator: General Moderators
-
saryon
- Forum Newbie
- Posts: 8
- Joined: Fri Jul 05, 2002 2:59 am
- Location: Leiden, Netherlands
- Contact:
php networking
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
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
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.
-
saryon
- Forum Newbie
- Posts: 8
- Joined: Fri Jul 05, 2002 2:59 am
- Location: Leiden, Netherlands
- Contact:
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.
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.
File sharing?
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.
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.
-
saryon
- Forum Newbie
- Posts: 8
- Joined: Fri Jul 05, 2002 2:59 am
- Location: Leiden, Netherlands
- Contact:
multi connection socket works !!!!!!!!!!!!!!!!!!!!!!!!!! :)
woohooo

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:
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ї$i]
do
{
socketlistї0] = listensocket
set all clientsockets in socketlist
nready = socket_select($listensocket, null, null, 0 0)
if(inarray(lsitensocket, socketlist)
{
loop through socketlist
{
if(client isn't a resource)
create new socket
else
send/receive data
}
}
} while(true)-
saryon
- Forum Newbie
- Posts: 8
- Joined: Fri Jul 05, 2002 2:59 am
- Location: Leiden, Netherlands
- Contact:
Re: File sharing?
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.
Good job
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...
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...
-
saryon
- Forum Newbie
- Posts: 8
- Joined: Fri Jul 05, 2002 2:59 am
- Location: Leiden, Netherlands
- Contact:
Re: Good job
thanksame12 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...
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.