Only variables can be passed by reference

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

Post Reply
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Only variables can be passed by reference

Post by shivam0101 »

I tried this tutorial, http://devzone.zend.com/node/view/id/1086 - The making of a real server

in line 30, i am getting an error,
Only variables can be passed by reference
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Interesting. And do you have a question?

p.s. What is line 30 of your script?
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

Code: Select all

$ready = socket_select($read,null,null,null);
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

$ready = socket_select($read,$write=null,$ex=null);
instead.
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

thanks, that error vanished, i am getting a warning,

Warning: socket_bind() [function.socket-bind]: unable to bind address [0]: Only one usage of each socket address (protocol/network address/port) is normally permitted. in C:\wamp\www\zend.php on line 16
Could not bind to address

i modified the code to,

Code: Select all

$address = $_SERVER['REMOTE_ADDR'];
$port = 80;
$max_clients = 10;
at the top.



line 16 :

Code: Select all

socket_bind($sock, $address, $port) or die('Could not bind to address');
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

please try

Code: Select all

echo "socket_bind($sock, $address, $port) or die('Could not bind to address');\n";
socket_bind($sock, $address, $port) or die('Could not bind to address');
shivam0101
Forum Contributor
Posts: 197
Joined: Sat Jun 09, 2007 12:09 am

Post by shivam0101 »

Code: Select all

$address=$_SERVER['REMOTE_ADDR'];
//$address = '192.168.0.100';
$port = 120;
$max_clients = 10;

Code: Select all

echo "socket_bind($sock, $address, $port) or die('Could not bind to address')\n";
socket_bind($sock, $address, $port) or die('Could not bind to address');

output:

socket_bind(Resource id #2, 192.168.0.1, 120) or die('Could not bind to address');
Warning: socket_bind() [function.socket-bind]: unable to bind address [0]: Only one usage of each socket address (protocol/network address/port) is normally permitted.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

The error message pretty much says it all: Another socket is already bound to that port and you cannot bind more than one at a time to a certain port number.
Do you run this code in a loop or something?
Post Reply