PHPBuilder - Using Sockets in PHP Page 3



RSS Twitter
Articles Php Functions

Using Sockets in PHP - Page 3

by: Armel Fauveau
|
May 10, 2001

Using sockets in PHP : Get articles from Usenet

Getting some articles

Now that we have the article number of the latest article, it is easy to get the latest ten articles. RFC977 says the ARTICLE command can be both used with the article number or the its Message ID.
Be careful here. The article number is different from its Message ID, as every news server will assign its own, so the article number of the same article will not be the same on two different news servers, whereas the message ID, included in the articles's header, is unique.

<?php

$cfgLimit    
10;

// upload last articles

$boucle=$last-$cfgLimit;

while (
$boucle <= $last) {

    
set_time_limit(0);

    
fputs($usenet_handle"ARTICLE $boucle\n");
    
    
$article="";
    
$tmp fgets($usenet_handle4096);
    if(
substr($tmp,0,3) != "220") {
        echo 
"+----------------------+\n";
        echo 
"Error on article $boucle\n";
        echo 
"+----------------------+\n";
    }
    else {
        while(
$tmp!=".\r\n") {
            
$tmp fgets($usenet_handle4096);
            
$article $article.$tmp;
        }
        
        echo 
"+----------------------+\n";
        echo 
"Article $boucle\n";
        echo 
"+----------------------+\n";
        echo 
"$article\n";
    }    

    
$boucle++;
}

?>
We just retrieved the ten latest articles available for this newsgroup on this server. It is also posible to get only the article's header, thanks to the HEAD command, or only the text using the BODY command.

« Previous Page
1
|
2
|
3
|
4
Next Page »

Comment and Contribute

Your comment has been submitted and is pending approval.

Author:
Armel Fauveau

Comment:



Comment:

(Maximum characters: 1200). You have characters left.