Home > Backend Development > PHP Tutorial > Using sockets to get articles from newsgroups 3_PHP tutorial

Using sockets to get articles from newsgroups 3_PHP tutorial

WBOY
Release: 2016-07-13 17:29:00
Original
812 people have browsed it

Reading Articles
Now that we have the article number of the last article, it is easy to read the last ten articles. RFC977 says that the ARTICLE command can use either the article number or its message ID.
It should be noted here that the article number is different from its message ID, because each news server assigns its own article number, so The number of the same article on two different servers is different, and the message ID of the article is included in the header information of the article and is unique.
$cfgLimit =10;
//upload last articles
$boucle = $last-$cfgLimit;
while ($boucle set_time_limit(0);
fputs($usenet_handle, "ARTICLE $bouclen");
$article="";
$tmp=fgets($usenet_handle, 4069);
if(substr( $tmp,0,3) != "220") {
echo "+---------------------+n";
echo "Error on article $bouclen";
echo "+----------------------+n";
}
else {
while($tmp!=".rn") {
$tmp = fgets($usenet_handle, 4096);
$article .=$tmp;
}
echo "+-- --------------------+n";
echo "Article $bouclen";
echo "+---------- ------------+n";


echo "$articlen";
}
$boucle++;
}
?>
We read the last ten articles from this newsgroup on the server. You can also use the HEAD command to read the header information of the article, or the BODY command to read the article content.
Close the connection
Finally, close the socket by calling the fclose() function to end the conversation with the NNTP server.
//close connection
fclose($usenet_handle);
?>
For more information about fclose(), please refer to http://www.php.net /manual/function.fclose.php
Conclusion
Above, we saw how to open, use and then close a socket: connect to an NNTP server and retrieve some articles. Publishing an article using the POST command is not much more complicated.
The next step is to write a WEB-based newsgroup client.
It is also very easy to store these articles and index them using a search engine (such as http://www.htdig.org). In this way, you have a web-based program for searching newsgroups.
An example of such a program can be found at http://www.phpindex.com/ng/.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/531731.htmlTechArticleRead article Now that we have got the article number of the last article, reading the last ten articles is Very easy. RFC977 says that the ARTICLE command can be used to edit articles...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template