PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hareldo
Forum Newbie
Posts: 8 Joined: Sun Jun 22, 2008 7:50 am
Post
by hareldo » Sat Jan 03, 2009 3:02 pm
when i run this code:
Code: Select all
<?php
set_time_limit (0);
$address = '127.0.0.1';
$port = 1234;
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Could not bind to address');
socket_listen($sock);
$client = socket_accept($sock);
socket_close($sock);
?>
sometimes its work but sometimes its doesnt work.what can be the problem?
it2051229
Forum Contributor
Posts: 312 Joined: Tue Dec 25, 2007 8:34 pm
Post
by it2051229 » Sat Jan 03, 2009 6:38 pm
interesting.... what're you trying to achieve? some computer going to connect into your socket? or your computer going to connect to someone's socket?
hareldo
Forum Newbie
Posts: 8 Joined: Sun Jun 22, 2008 7:50 am
Post
by hareldo » Sun Jan 04, 2009 9:39 am
some computer going to connect to this socket.
do you have another way to do this?
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Sun Jan 04, 2009 9:53 am
Maybe you have more than one instance of this PHP script running at a time - after the first one has binded to this port every other attempt to bind to this port will fail.
There are 10 types of people in this world, those who understand binary and those who don't
hareldo
Forum Newbie
Posts: 8 Joined: Sun Jun 22, 2008 7:50 am
Post
by hareldo » Sun Jan 04, 2009 11:00 am
how it possible that this script run more then one time?
VladSun
DevNet Master
Posts: 4313 Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria
Post
by VladSun » Sun Jan 04, 2009 12:19 pm
How do you run this script? Console? Apache?
sometimes its work but sometimes its doesnt work.
Could you be more specific - it's hard for me to guess what "is not working"
There are 10 types of people in this world, those who understand binary and those who don't
hareldo
Forum Newbie
Posts: 8 Joined: Sun Jun 22, 2008 7:50 am
Post
by hareldo » Sun Jan 04, 2009 1:47 pm
run with apache(on windows).
its show me an error about the socket_bind()