Hi!
I've read the aricle "Using sockets in PHP" at phpbuilder.com, and I've managed to connect to a newsserver, and getting the numbers for the first and last message. But when I try to get the actual messages, nothing happens.
It works fine until I insert the piece of code that gets the messages.
Here it is:
<?php
//-------------------------------------------------
// connect to newsserver
//-------------------------------------------------
$cfgServer = "news.cybercity.dk";
$cfgPort = 119;
$cfgTimeOut = 10;
// open a socket
if(!$cfgTimeOut)
// without timeout
$usenet_handle = fsockopen($cfgServer, $cfgPort);
else
// with timeout
$usenet_handle = fsockopen($cfgServer, $cfgPort, &$errno, &$errstr, $cfgTimeOut);
if(!$usenet_handle) {
echo "Could not connect to " . $cfgServer . "<br>";
exit();
}
else {
echo "Not connected to: " . $cfgServer . "<br>";
$tmp = fgets($usenet_handle, 1024);
}
//-------------------------------------------------
// choose newsgroup
//-------------------------------------------------
// select newsgroup
$cfgNewsGroup = "dk.test";
fputs($usenet_handle, "GROUP ".$cfgNewsGroup."\n");
$tmp = fgets($usenet_handle, 1024);
if($tmp == "480 Authentication required for command\r\n") {
echo "$tmp\n";
exit();
}
$info = split(" ", $tmp);
$messages = $info[1];
$first = $info[2];
$last = $info[3];
echo "Number of messages: " . $messages . "<br>";
echo "First: " . $first . "<br>";
echo "Last: " . $last . "<br><br>";
//-------------------------------------------------
// Get messages
//-------------------------------------------------
$cfgLimit = 10;
$boucle=$last-$cfgLimit;
while ($boucle <= $last) {
set_time_limit(0);
fputs($usenet_handle, "ARTICLE $boucle<br>");
$article="";
$tmp = fgets($usenet_handle, 4096);
if(substr($tmp,0,3) != "220") {
echo "+----------------------+<br>";
echo "Error on article $boucle<br>";
echo "+----------------------+<br>";
}
else {
while($tmp!=".\r\n") {
$tmp = fgets($usenet_handle, 4096);
$article = $article.$tmp;
}
echo "+----------------------+<br>";
echo "Article $boucle\n";
echo "+----------------------+<br>";
echo "$article<br>";
}
$boucle++;
}
fclose($usenet_handle);
?>