| 3 comments ]

Consider the following PHP script:


<?php
function get_socket($host, $port) {
$fr = fsockopen($host, $port);
stream_set_blocking($fr, false);
return $fr;
}

// Assume $host1, $host2, etc are defined properly
$write_map[] = array('fr' => get_socket($host1, $port1),
'data' => str_pad("", 500000, "A"));
$write_map[] = array('fr' => get_socket($host2, $port2),
'data' => str_pad("", 500000, "B"));
$write_map[] = array('fr' => get_socket($host3, $port3),
'data' => str_pad("", 500000, "C"));

do {
$write_sockets = array();

foreach($write_map as $data) {
$write_sockets[] = $data['fr'];
}

$num_returned = stream_select($r = null, $write_sockets, $e = null, 30);

if($num_returned) {
foreach($write_sockets as $fr) {
foreach($write_map as $index => $data) {
if($data['fr'] === $fr) {
$len = fwrite($fr, $data['buf']);

if($len) {
$data['buf'] = substr($data['buf'], $len);

if(empty($data['buf'])) {
fclose($data['fr']);
/* ????????? */
}
}
}
}
}
}
} while(count($write_map));
?>

What should go in the ??????? above for this script to function properly?

Please answer through the comments I will make it publish on blog..............

3 comments

denis said... @ Tuesday, June 10, 2008 at 8:47:00 PM GMT+1

I had this one in the mok exam .. I can"t find the answer. please help !

Unknown said... @ Wednesday, August 12, 2009 at 12:59:00 PM GMT+1

answer is
unset($write_map[$index]);

Unknown said... @ Wednesday, August 12, 2009 at 1:00:00 PM GMT+1

answer is
unset($write_map[$index]);

Post a Comment

Please put your comments here. your questions, your suggestions, also what went wrong with me.