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..............
[Thursday, February 21, 2008
|
3
comments
]
Popular Posts
- php questions
- some php questions
- How to create a plugin in elgg.
- php Questions
- Mysql query for searching a value, add weightage on the number of occurances and sort based on the weight-age
- Contact Me
- solving the packaging problem in PHP
- How to add or remove WWW on URLs using htaccess.
- php questions
- Inserting nodes into xml files using XML DOM in PHP .
3 comments
I had this one in the mok exam .. I can"t find the answer. please help !
answer is
unset($write_map[$index]);
answer is
unset($write_map[$index]);
Post a Comment
Please put your comments here. your questions, your suggestions, also what went wrong with me.