search
Homephp教程php手册使用sockets:从新闻组中获取文章(三)

使用sockets:从新闻组中获取文章(三)

Jun 13, 2016 pm 12:42 PM
socketsthreeuseusarticlemostat lastofserial numberObtainread

读取文章
    既然我们已经得到了最后一篇文章的文章编号,读取最后的十篇文章就是很容易的事了。RFC977中说,ARTICLE命令既可以使用文章编号,也可以使用它的消息ID.
    这里要注意,文章编号跟它的消息ID是不同的,因为每个新闻服务器分配自己的文章编号,所以同一篇文章在两个不同的服务器上的编号是不一样的,而文章的消息ID,是包括在文章的头信息里,并且是唯一的。

        $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++;
  }

  ?>

    我们从服务器的这个新闻组中读取了最后的十篇文章,。也可以通过使用HEAD命令读取文章的头信息,或者使用BODY命令读取文章内容。

关闭连接
    最后,通过调用fclose()函数关闭socket,结束同NNTP服务器的对话。

          //close connection
      fclose($usenet_handle);
    ?>
    关于fclose()的更多信息,请参考 http://www.php.net/manual/function.fclose.php

结论
    在上文中,我们看到了怎样打开、使用然后关闭一个socket:连接到一个NNTP服务器,取回一些文章。使用POST命令发表文章也复杂不到哪儿去。
    下一步就是编写一个基于WEB的新闻组客户端了。
    存储这些文章,用某个搜索引擎(比如说http://www.htdig.org)对文章进行索引也是非常容易的。这样,你有了一个基于web的搜索新闻组的程序了。
    这样的程序的一个例子可以在http://www.phpindex.com/ng/得到。 

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software