Home » Networking » Net_NNTP » Manual
Implementation of the NNTP protocol
Net_NNTP_Client
NNTP client implementation
Constants
Constants – predefined constants
NET_NNTP_PROTOCOL_DEFAULT_HOST
default NNTP hostname: localhost
NET_NNTP_PROTOCOL_DEFAULT_PORT
default NNTP port: 119
NET_NNTP_AUTHORIGINAL
authentication provided by the NNTP-server
NET_NNTP_AUTHSIMPLE
authentication provided by the NNTP-server
NET_NNTP_AUTHGENERIC
authentication provided by the NNTP-server
Net_NNTP_Client::authenticate()
Net_NNTP_Client :: () – Authenticate
Synopsis
require_once 'Net/NNTP/Client.php';
public booleanNet_NNTP_Client::authenticate
(
string
$$user
,
string
$$pass
[,
integer
$$authmode = NET_NNTP_AUTHORIGINAL
] )
Description
Authenticate on an already open connection
Parameter
-
$user- Username to authenticate with -
$pass- Password to authenticate with -
$authmode- Type of authentication. Default=NET_NNTP_AUTHORIGINAL
Return value
boolean -
Returns TRUE on success,
PEAR_Error on failure.
Note
This function can not be called statically.
See
Net_NNTP_Client::connect()
Net_NNTP_Client::connect() – Connects to a NNTP-server
Synopsis
require_once 'Net/NNTP/Client.php';
boolean Net_NNTP_Client::connect (
string $host = NET_NNTP_PROTOCOL_DEFAULT_HOST
,
integer $port = NET_NNTP_PROTOCOL_DEFAULT_PORT
)
Description
Connect to a specific NNTP-server
Parameter
-
$host- Hostname of the NNTP-server. Default=NET_NNTP_PROTOCOL_DEFAULT_HOST -
$port- Port, where the NNTP-server listens. Default=NET_NNTP_PROTOCOL_DEFAULT_PORT
Return value
boolean -
Returns TRUE on success,
PEAR_Error on failure.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL |
"Could not connect to NNTP-server $host"
or
"Not connected"
|
The connection couldn't be established because
|
Check for server name, the connection to the net and possible firewalls on client or server side. |
Note
This function can not be called statically.
See
Net_NNTP::quit(), Net_NNTP::pepareConnection()
Example
Using connect()
<?php
require_once 'Net/NNTP/Client.php';
$nntp = new Net_NNTP_Client();
$ret = $nntp->connect('news.php.net');
if( PEAR::isError($ret)) {
// handle error
} else {
// success
}
?>
Net_NNTP_Client::connectAuthenticated()
Net_NNTP_Client::connectAuthenticated() – Connect and authenticate to a NNTP-server
Synopsis
require_once 'Net/NNTP/Client.php';
boolean Net_NNTP_Client::connectAuthenticated (
integer $user
= null
,
integer $pass
= null
,
string $host = NET_NNTP_PROTOCOL_DEFAULT_HOST
,
integer $port = NET_NNTP_PROTOCOL_DEFAULT_PORT
,
integer $authmode = NET_NNTP_AUTHORIGINAL
)
Description
Connect and authenticate to a specific NNTP-server
This function is deprecated. That means that future versions of this package may not support it anymore.
Parameter
-
$user- Username to authenticate -
$pass- Password to authenticate -
$host- Hostname of the NNTP-server. Default=NET_NNTP_PROTOCOL_DEFAULT_HOST -
$port- Port, where the NNTP-server listens. Default=NET_NNTP_PROTOCOL_DEFAULT_PORT -
$authmode- Type of authentication. Default=NET_NNTP_AUTHORIGINAL
Return value
boolean -
Returns TRUE on success,
PEAR_Error on failure.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL |
"Could not connect to NNTP-server $host"
or
"Not connected"
|
The connection couldn't be established because
|
Check for server name, the connection to the net and possible firewalls on client or server side. |
Note
since 0.3
This function can not be called statically.
See
Net_NNTP_Client::connect() Net_NNTP_Client::quit(),
Example
Using connectauthenticated()
<?php
require_once 'Net/NNTP/Client.php';
$nntp = new Net_NNTP_Client();
$ret = $nntp->connectAuthenticated('news.php.net');
if( PEAR::isError($ret)) {
// handle error
} else {
// success
}
?>
Net_NNTP_Client::count()
Net_NNTP_Client :: () – Get the number of articles in the current newsgroup
Synopsis
require_once 'Net/NNTP/Client.php';
public integerNet_NNTP_Client::count
( void
)
Description
Retrieves the number of articles in the current newsgroup.
Return value
integer - number of articles in newsgroup
Note
since 0.3
This function can not be called statically.
Example
Using count()
<?php
...
$nntp->selectGroup("php.pear.dev");
echo "number of articles: ".$nntp->count();
?>
Net_NNTP_Client::getDescriptions()
Net_NNTP_Client :: () – Synopsis require_once 'Net/NNTP/Client.php'; public boolean Net_NNTP_Client::getDescriptions ( void ) This method is currently not documented. This function is EXPERIMENTAL. That means, that the behaviour of this function, the function name, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this function at your own risk. Description
Net_NNTP_Client::first()
Net_NNTP_Client :: () – Get the number of the first article in the current newsgroup
Synopsis
require_once 'Net/NNTP/Client.php';
public integerNet_NNTP_Client::first
( void
)
Description
Retrieves the number of the first article in the current newsgroup.
Return value
integer - lowest article number in newsgroup
Note
since 0.3
This function can not be called statically.
Example
Using first()
<?php
...
$nntp->selectGroup("php.pear.dev");
echo "lowest message number: ".$nntp->first();
?>
Net_NNTP_Client::getArticle()
Net_NNTP_Client::getArticle() – Fetch an article from the NNTP-server
Synopsis
require_once 'Net/NNTP/Client.php';
mixed Net_NNTP_Client::getArticle (
string $article
)
Description
This function is currently not documented.
See
Net_NNTP_Client::getArticleRaw()
Net_NNTP_Client::getArticleRaw() – Fetch an article from the NNTP-server
Synopsis
require_once 'Net/NNTP/Client.php';
mixed Net_NNTP_Client::getArticleRaw (
string $article
,
boolean $implode = false
)
Description
Returns the whole article from the currently selected newsgroup
Parameter
-
string $article- article number or Message-ID of the article to fetchboolean $implode- Determines if the resulting array is to be imploded into a string.
Return value
array/string - If message exists the message
or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article |
Note
since 0.3
This function can not be called statically.
See
Net_NNTP_Client::getArticle() , Net_NNTP_Client::getHeaderRaw() , Net_NNTP_Client::getBodyRaw()
Example
Using getArticleRaw()
<?php
...
$article = $nntp->getArticleRaw($msg_id);
if( PEAR::isError($article)) {
// handle error
} else {
// success
}
?>
Net_NNTP_Client::getGroupArticles()
Net_NNTP_Client :: () – Synopsis require_once 'Net/NNTP/Client.php'; public boolean Net_NNTP_Client::getGroupArticles ( string $$newsgroup ) This method is currently not documented. This function is EXPERIMENTAL. That means, that the behaviour of this function, the function name, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this function at your own risk. Description
Net_NNTP_Client::getBodyRaw()
Net_NNTP_Client::getBodyRaw() – Fetch the body of an article from the NNTP-server
Synopsis
require_once 'Net/NNTP/Client.php';
mixed Net_NNTP_Client::getBodyRaw (
string $article
,
boolean $implode = false
)
Description
Returns the whole body of an article from the currently selected newsgroup
Parameter
-
string $article- article number or Message-ID of the article to fetchboolean $implode- Determines if the resulting array is to be imploded into a string.
Return value
string/array - If message exists the body
or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article |
Note
since 0.3
This function can not be called statically.
getBody() makes no converting of the body content to any character set. You get the content 'as is'.
See
Net_NNTP_Client::getHeaderRaw() , Net_NNTP_Client::getArticleRaw()
Example
Using getBodyRaw()
<?php
...
$body = $nntp->getBodyRaw($msgId);
if( PEAR::isError($body)) {
// handle error
} else {
// success - print body
echo $body;
}
?>
Net_NNTP_Client::getDate()
Net_NNTP_Client::getDate() – Get date from NNTP-server
Synopsis
require_once 'Net/NNTP/Client.php';
mixed Net_NNTP_Client::getDate (
integer $format = 1
)
Description
Retrieves the date from the NNTP-server.
Parameter
-
$format- Tetermines which format to return.
Return value
| $format | returns |
|---|---|
| 0 |
timestamp
|
| 1 |
array - a hash with the date
|
Note
since 0.3
This function can not be called statically.
Example
Using getDate()
<?php
...
$date = $nntp->getDate();
echo "Date: ".$date['m']."-".$date['d']."-".$date['y'];
?>
Net_NNTP_Client::getGroups()
Net_NNTP_Client::getGroups() – Fetch list of avaible newsgroups
Synopsis
require_once 'Net/NNTP/Client.php';
array Net_NNTP_Client::getGroups (
)
Description
Returns a list of all avaible newsgroups
Return value
array - a two dimensional, nested array
indicated by the name of the newsgroup, every entry contains
information about the newsgroup:
-
$groups[newsgroup_name]['group']Name of the newsgroup -
$groups[newsgroup_name]['last']Number of the last article -
$groups[newsgroup_name]['first']Number of the first article -
$groups[newsgroup_name]['posting']values:y- yes,n- no,m- moderated)
Note
This function can not be called statically.
Especially public news server can provide more then 30.000 newsgroup. So this function may runs longer then the maximum execution time set in the
php.ini.
See
Net_NNTP_Client::selectGroup()
Example
Using getGroups()
<?php
...
$ret = $nntp->connect('news.php.net');
if( PEAR::isError($ret)) {
// handle error
} else {
// success
$groups = $nntp->getGroups();
// Print a list of avaible newsgroups
foreach($groups as $group) {
echo $group['group'].'<br>';
}
}
?>
Net_NNTP_Client::getHeader()
Net_NNTP_Client::getHeader() – Fetch the header of an article from the NNTP-server
Synopsis
require_once 'Net/NNTP/Client.php';
object Net_NNTP_Client::getHeader (
string $article
)
Description
This function is currently not documented.
See
Net_NNTP_Client::getHeaderRaw()
Net_NNTP_Client::getHeaderRaw() – fetch message header
Synopsis
require_once 'Net/NNTP/Client.php';
string Net_NNTP_Client::getHeaderRaw (
string $article
,
boolean $implode = false
)
Description
Returns the whole header of an article in the currently selected newsgroup
Parameter
-
string $article- article number or Message-ID of the article to fetchboolean $implode- Determines if the resulting array is to be imploded into a string.
Return value
array/string - If message exists the header
or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article |
Note
since 0.3
This function can not be called statically.
See
Net_NNTP_Client::getHeader() , Net_NNTP_Client::getArticleRaw() , Net_NNTP_Client::getBodyRaw()
Example
Using getHeaderRaw()
<?php
...
$headers = $nntp->getHeaderRaw($msgId);
if( PEAR::isError($headers)) {
// handle error
} else {
// success - split the string into a array
$headersArray = explode( "\n", $headers);
}
?>
Net_NNTP_Client::getNewGroups()
Net_NNTP_Client :: () – Synopsis require_once 'Net/NNTP/Client.php'; public boolean Net_NNTP_Client::getNewGroups ( mixed $$time ) This method is currently not documented. This function is EXPERIMENTAL. That means, that the behaviour of this function, the function name, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this function at your own risk. Description
Net_NNTP_Client::getNewNews()
Net_NNTP_Client :: () – Synopsis require_once 'Net/NNTP/Client.php'; public boolean Net_NNTP_Client::getNewNews ( mixed $$time [, string $$pass ] ) This method is currently not documented. This function is EXPERIMENTAL. That means, that the behaviour of this function, the function name, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this function at your own risk. Description
Net_NNTP_Client::getOverview()
Net_NNTP_Client::getOverview() – Fetch newsgroup overview
Synopsis
require_once 'Net/NNTP/Client.php';
array Net_NNTP_Client::getOverview (
string $first
,
string $last
)
Description
Returns (a certain range of) the overview of the currently selected newsgroup. selected newsgroup
Parameter
-
$first- first article number, start of the range -
$last- last article number, end of the range
Return value
array - a nested array
indicated by the message id of the article, every entry contains
the header as array
<?php
$msgs[message_id][headername] = headercontent
?>
Note
This function can not be called statically.
Be careful with choosing the range. It could requires some time to get a huge number of message headers.
See
Net_NNTP_Client::getOverviewFormat()
Example
Using getOverview()
<?php
...
$ret = $nntp->connect('news.php.net');
if( PEAR::isError($ret)) {
// handle error
} else {
// print the last 10 messages
$data = $nntp->selectGroup('php.pear.dev');
$msgs = $nntp->getOverview( $data['last'] - 10, $data[last]);
foreach($msgs as $msg) {
// print subjects
echo $msg['subject'].'<br>';
}
}
?>
Net_NNTP_Client::getReferencesOverview()
Net_NNTP_Client :: () – Synopsis require_once 'Net/NNTP/Client.php'; public boolean Net_NNTP_Client::getReferencesOverview ( integer $$first , integer $$last ) This method is currently not documented. This function is EXPERIMENTAL. That means, that the behaviour of this function, the function name, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this function at your own risk. Description
Net_NNTP_Client::group()
Net_NNTP_Client :: () – Synopsis require_once 'Net/NNTP/Client.php'; public boolean Net_NNTP_Client::group ( string $$user , string $$pass [, integer $$authmode = NET_NNTP_AUTHORIGINAL ] ) This method is currently not documented. This function is EXPERIMENTAL. That means, that the behaviour of this function, the function name, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this function at your own risk. Description
Net_NNTP_Client::isConnected()
Net_NNTP_Client :: () – Connected?
Synopsis
require_once 'Net/NNTP/Client.php';
public booleanNet_NNTP_Client::isConnected
( void
)
This method is currently not documented.
This function is EXPERIMENTAL. That means, that the behaviour of this function, the function name, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this function at your own risk.
Description
Net_NNTP_Client::last()
Net_NNTP_Client :: () – Get the number of the last article in the current newsgroup
Synopsis
require_once 'Net/NNTP/Client.php';
public integerNet_NNTP_Client::last
( void
)
Description
Retrieves the number of the last article in the current newsgroup.
Return value
integer - highest article number in newsgroup
Note
since 0.3
This function can not be called statically.
Example
Using last()
<?php
...
$nntp->selectGroup("php.pear.dev");
echo "highest message number: ".$nntp->last();
?>
Net_NNTP_Client::post()
Net_NNTP_Client :: () – Synopsis require_once 'Net/NNTP/Client.php'; public boolean Net_NNTP_Client::post ( string $$newsgroups , string $$subject , string $$body , string $$from [, integer $$additional = '' ] ) This method is currently not documented. This function is EXPERIMENTAL. That means, that the behaviour of this function, the function name, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this function at your own risk. Description
Net_NNTP_Client::quit()
Net_NNTP_Client :: () – Close the connection to the NNTP-server
Synopsis
require_once 'Net/NNTP/Client.php';
public voidNet_NNTP_Client::post
( void
)
Description
Close the connection to the NNTP-server
Note
This function can not be called statically.
See
Net_NNTP_Client::selectGroup()
Net_NNTP_Client::selectGroup() – select a newsgroup
Synopsis
require_once 'Net/NNTP/Client.php';
array Net_NNTP_Client::selectGroup (
string $newsgroup
)
Description
Selects a specific newsgroup on the NNTP-server
Parameter
-
string
$newsgroup- Name of the newsgroup to access
Return value
array - If the newsgroup exists, an array
is returned:
| Key | Value |
|---|---|
| 'count' | Number of articles in the group |
| 'first' | The first article number in the group |
| 'last' | The last article number in the group |
| 'group' | Groupname |
otherwise a PEAR_Error is returned on fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article |
Note
This function can not be called statically.
See
Net_NNTP_Client::connect() , Net_NNTP_Client::getGroups()
Example
Using selectGroup()
<?php
...
$ret = $nntp->connect('news.php.net');
if( PEAR::isError($ret)) {
// handle error
} else {
// success
$data = $nntp->selectGroup('php.pear.dev');
// Print the count of articles
echo "Count: ", $data['last'] - $data['first'];
}
?>
Net_NNTP
This function is deprecated. That means that future versions of this package may not support it anymore.
The historical Net_NNTP class
Constants
Constants – predefined constants
NET_NNTP_PROTOCOL_DEFAULT_HOST
default NNTP hostname: localhost
NET_NNTP_PROTOCOL_DEFAULT_PORT
default NNTP port: 119
NET_NNTP_AUTHORIGINAL
authentication provided by the NNTP-server
NET_NNTP_AUTHSIMPLE
authentication provided by the NNTP-server
NET_NNTP_AUTHGENERIC
authentication provided by the NNTP-server
PEAR_NNTP_ALL
deprecated (never used)
PEAR_NNTP_LIST
deprecated (never used)
PEAR_NNTP_NAMES
deprecated (never used)
PEAR_NNTP_AUTHORIGINAL
deprecated (use NET_NNTP_AUTHORIGINAL instead)
PEAR_NNTP_AUTHSIMPLE
deprecated (use NET_NNTP_AUTHSIMPLE instead)
PEAR_NNTP_AUTHGENERIC
deprecated (use NET_NNTP_AUTHGENERIC instead)
Net_NNTP::command()
Net_NNTP::command() – send a command to a newsserver
Synopsis
require_once 'Net/NNTP.php';
string Net_NNTP::command (
string $cmd
,
boolean $auth
)
Description
Command() sends a string command to a newsserver. So you can send customized and/ or non-standard commands to the newsserver.
Parameter
-
string $cmd- the command to send -
boolean $auth- if TRUE, an auth request is issued before the command
Return value
string - the unprocessed server response
Note
This function can not be called statically.
Command() does no checks on the given command and/ or proccesses the server response. So you should know what are you doing.
Example
Using command()
<?php
...
$response = $nntp->command("ARTICLE 1004853");
?>
Net_NNTP::connect()
Net_NNTP::connect() – Connects to a newsserver
Synopsis
require_once 'Net/NNTP.php';
boolean Net_NNTP::connect (
string $host = NET_NNTP_PROTOCOL_DEFAULT_HOST
,
integer $port = NET_NNTP_PROTOCOL_DEFAULT_PORT
)
Description
Connect to a specific newsserver
Parameter
-
$host- Hostname of the newsserver -
$port- Port, where the newsserver listens
Return value
boolean -
Returns TRUE on success,
PEAR_Error on failure.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL |
"Could not connect to NNTP-server $host"
or
"Not connected"
|
The connection couldn't be established because
|
Check for server name, the connection to the net and possible firewalls on client or server side |
Note
This function can not be called statically.
See
Net_NNTP::quit(), Net_NNTP::pepareConnection()
Example
Using connect()
<?php
require_once "Net/NNTP.php";
$nntp = new Net_NNTP;
$ret = $nntp->connect("news.php.net");
if( PEAR::isError($ret)) {
// handle error
} else {
// success
}
?>
Net_NNTP::connectAuthenticated()
Net_NNTP::connectAuthenticated() – Connects and authenticates to a newsserver
Synopsis
require_once 'Net/NNTP.php';
boolean Net_NNTP::connectAuthenticated (
integer $user
= null
,
integer $pass
= null
,
string $host = NET_NNTP_PROTOCOL_DEFAULT_HOST
,
integer $port = NET_NNTP_PROTOCOL_DEFAULT_PORT
,
integer $authmode = NET_NNTP_AUTHORIGINAL
)
Description
Connect and authenticate to a specific newsserver
Parameter
-
$user- Username to authenticate -
$pass- Password to authenticate -
$host- Hostname of the NNTP-server -
$port- Port, where the newsserver listens -
$authmode- Type of authentication, at the moment only NET_NNTP_AUTHORIGINAL
Return value
boolean -
Returns TRUE on success,
PEAR_Error on failure.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL |
"Could not connect to NNTP-server $nntpserver"
or
"Not connected"
|
The connection couldn't be established because
|
Check for server name, the connection to the net and possible firewalls on client or server side |
Note
since 0.3
This function can not be called statically.
See
Net_NNTP::connect() Net_NNTP::quit(),
Example
Using connectauthenticated()
<?php
require_once "Net/NNTP.php";
$nntp = new Net_NNTP;
$ret = $nntp->connectAuthenticated("news.php.net");
if( PEAR::isError($ret)) {
// handle error
} else {
// success
}
?>
Net_NNTP::date()
Net_NNTP::date() – get date from news server
Synopsis
require_once 'Net/NNTP.php';
array Net_NNTP::date (
)
Description
This function is deprecated. That means that future versions of this package may not support it anymore.
Retrieves the date from the news server
Return value
array - a hash with the date
-
$date['y']Year -
$date['m']Month -
$date['d']Day
Note
This function can not be called statically.
Example
Using date()
<?php
...
$date = $nntp->date();
echo "Date: ".$date['m']."-".$date['d']."-".$date['y'];
?>
Net_NNTP::first()
Net_NNTP::first() – get lowest message number
Synopsis
require_once 'Net/NNTP.php';
integer Net_NNTP::first (
)
Description
Retrieves the lowest message number in the current selected newsgroup
Return value
integer - lowest message number
Note
since 0.3
This function can not be called statically.
Example
Using first()
<?php
...
$nntp->selectGroup("php.pear.dev");
echo "lowest message number: ".$nntp->first();
?>
Net_NNTP::getArticle()
Net_NNTP::getArticle() – fetch an article from a new server
Synopsis
require_once 'Net/NNTP.php';
mixed Net_NNTP::getArticle (
string $articleId
)
Description
Returns the whole article from the current selected newsgroup
This function is deprecated. That means that future versions of this package may not support it anymore.
Consider this method deprecated and subject to changes - use Net_NNTP::getArticleRaw() instead.
Parameter
-
string $articleID- Message-ID of the message number to fetch
Return value
string - If message exists the message
as string or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article | Check the article ID or if your are still connected to the server ( Net_NNTP::isConnected()) |
Note
This function can not be called statically.
See
Net_NNTP::getHeaders() , Net_NNTP::getBody() , Net_NNTP::getOverview()
Example
Using getArticle()
<?php
...
$article = $nntp->getArticle($msg_id);
if( PEAR::isError($article)) {
// handle error
} else {
// success
}
?>
Net_NNTP::getArticleRaw()
Net_NNTP::getArticleRaw() – fetch an article from a new server
Synopsis
require_once 'Net/NNTP.php';
mixed Net_NNTP::getArticleRaw (
string $articleId
)
Description
Returns the whole article from the current selected newsgroup
Parameter
-
string $articleID- Message-ID of the message number to fetch
Return value
string - If message exists the message
as string or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article | Check the article ID or if your are still connected to the server ( Net_NNTP::isConnected()) |
Note
since 0.3
This function can not be called statically.
See
Net_NNTP::getHeadersRaw() , Net_NNTP::getBodyRaw() , Net_NNTP::getOverview()
Example
Using getArticleRaw()
<?php
...
$article = $nntp->getArticleRaw($msg_id);
if( PEAR::isError($article)) {
// handle error
} else {
// success
}
?>
Net_NNTP::getBody()
Net_NNTP::getBody() – fetch the body of an article
Synopsis
require_once 'Net/NNTP.php';
string Net_NNTP::getBody (
string $articleId
)
Description
Returns the whole body of an article in the current selected newsgroup from the webserver
This function is deprecated. That means that future versions of this package may not support it anymore.
Consider this method deprecated and subject to changes - use Net_NNTP::getBodyRaw() instead.
Parameter
-
string
$articleId- Message-ID or Message number
Return value
string - If message exists the body as
string or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article | Check the article ID or if your are still connected to the server ( Net_NNTP::isConnected()) |
Note
This function can not be called statically.
getBody() makes no converting of the body content to any character set. You get the content 'as is'.
See
Net_NNTP::getHeaders() , Net_NNTP::splitHeaders() , Net_NNTP::getArticle() , Net_NNTP::getOverview()
Example
Using getBody()
<?php
...
$body = $nntp->getBody($msgId);
if( PEAR::isError($body)) {
// handle error
} else {
// success - print body
echo $body;
}
?>
Net_NNTP::getBodyRaw()
Net_NNTP::getBodyRaw() – fetch the body of an article
Synopsis
require_once 'Net/NNTP.php';
string Net_NNTP::getBodyRaw (
string $articleId
)
Description
Returns the whole body of an article in the current selected newsgroup from the webserver
Parameter
-
string
$articleId- Message-ID or Message number
Return value
string - If message exists the body as
string or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article | Check the article ID or if your are still connected to the server ( Net_NNTP::isConnected()) |
Note
since 0.3
This function can not be called statically.
getBody() makes no converting of the body content to any character set. You get the content 'as is'.
See
Net_NNTP::getHeaderRaw() , Net_NNTP::splitHeaders() , Net_NNTP::getArticleRaw() , Net_NNTP::getOverview()
Example
Using getBodyRaw()
<?php
...
$body = $nntp->getBodyRaw($msgId);
if( PEAR::isError($body)) {
// handle error
} else {
// success - print body
echo $body;
}
?>
Net_NNTP::getDate()
Net_NNTP::getDate() – get date from news server
Synopsis
require_once 'Net/NNTP.php';
array Net_NNTP::getDate (
)
Description
Retrieves the date from the news server
Return value
array - a hash with the date
-
$date['y']Year -
$date['m']Month -
$date['d']Day
Note
since 0.3
This function can not be called statically.
Example
Using getDate()
<?php
...
$date = $nntp->getDate();
echo "Date: ".$date['m']."-".$date['d']."-".$date['y'];
?>
Net_NNTP::getGroups()
Net_NNTP::getGroups() – fetch list of avaible newsgroups
Synopsis
require_once 'Net/NNTP.php';
array Net_NNTP::getGroups (
string $fetch
= true
)
Description
Returns a list of all avaible newsgroups from the connected news server
Parameter
-
$fetch- can be irgnored, unused
Return value
array - a two dimensional, nested array
indicated by the name of the newsgroup, every entry contains
information about the newsgroup:
-
$groups[newsgroup_name]['group']name of the newsgroup -
$groups[newsgroup_name]['last']message number of the last message -
$groups[newsgroup_name]['first']message number of the first message -
$groups[newsgroup_name]['posting_allowed']values:y- yes,n- no,m- moderated) -
$groups[newsgroup_name]['desc']newsgroup description
Note
This function can not be called statically.
Especially public news server can provide more then 30.000 newsgroup. So this function may runs longer then the maximum execution time set in the
php.ini.
See
Example
Using getGroups()
<?php
...
$ret = $nntp->connect("news.php.net");
if( PEAR::isError($ret)) {
// handle error
} else {
// success
$groups = $nntp->getGroups();
// Print a list of avaible newsgroups
foreach($groups as $group) {
echo $group['group'].': '.$group['desc'].'<br>';
}
}
?>
Net_NNTP::getHeaderRaw()
Net_NNTP::getHeaderRaw() – fetch message header
Synopsis
require_once 'Net/NNTP.php';
string Net_NNTP::getHeaderRaw (
string $articleId
)
Description
Returns all avaible header lines of a specified message in the current selected newsgroup
Parameter
-
string
$articleId- Message-ID or Message number
Return value
string - If message exists the header
as string or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article | Check the article ID or if your are still connected to the server ( Net_NNTP::isConnected()) |
Note
since 0.3
This function can not be called statically.
See
Net_NNTP::splitHeaders() , Net_NNTP::getBodyRaw() , Net_NNTP::getOverview()
Example
Using getHeaderRaw()
<?php
...
$headers = $nntp->getHeaderRaw($msgId);
if( PEAR::isError($headers)) {
// handle error
} else {
// success - split the string into a array
$headersArray = explode( "\n", $headers);
}
?>
Net_NNTP::getHeaders()
Net_NNTP::getHeaders() – fetch message headers
Synopsis
require_once 'Net/NNTP.php';
string Net_NNTP::getHeaders (
string $articleId
)
Description
Returns all avaible header lines of a specified message in the current selected newsgroup
This function is deprecated. That means that future versions of this package may not support it anymore.
Consider this method deprecated and subject to changes - use Net_NNTP::getHeaderRaw() instead.
Parameter
-
string
$articleId- Message-ID or Message number
Return value
string - If message exists the headers
as string or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article | Check the article ID or if your are still connected to the server ( Net_NNTP::isConnected()) |
Note
This function can not be called statically.
See
Net_NNTP::splitHeaders() , Net_NNTP::getBody() , Net_NNTP::getOverview()
Example
Using getHeaders()
<?php
...
$headers = $nntp->getHeaders($msgId);
if( PEAR::isError($headers)) {
// handle error
} else {
// success - split the string into a array
$headersArray = explode( "\n", $headers);
}
?>
Net_NNTP::getOverview()
Net_NNTP::getOverview() – fetch a number of message headers
Synopsis
require_once 'Net/NNTP.php';
array Net_NNTP::getOverview (
string $first
,
string $last
)
Description
Returns all message headers in a certain range of the current selected newsgroup
Parameter
-
$first- start message id, start of the range -
$last- last message id, end of the range
Return value
array - a nested array
indicated by the message id of the article, every entry contains
the header as array
<?php
$msgs[message_id][headername] = headercontent
?>
Note
This function can not be called statically.
Be careful with choosing the range. It could requires some time to get a huge number of message headers.
See
Example
Using getOverview()
<?php
...
$ret = $nntp->connect("news.php.net");
if( PEAR::isError($ret)) {
// handle error
} else {
// print the last 10 messages
$data = $nntp->selectGroup("php.pear.dev");
$msgs = $nntp->getOverview( $data['last'] - 10, $data[last]);
foreach($msgs as $msg) {
// print subjects
echo $msg['Subject'].'<br>';
}
}
?>
Net_NNTP::getOverviewFmt()
Net_NNTP::getOverviewFmt() – fetch the name of message headers
Synopsis
require_once 'Net/NNTP.php';
array Net_NNTP::getOverviewFmt (
)
Description
Returns the name of message headers, which is provided by every message
Return value
array - list of header names
Note
This function can not be called statically.
See
Example
Using getOverviewFmt()
<?php
...
$tblheaders = $nntp->getOverviewFmt();
// create a table headline
echo '<table>';
echo '<tr>';
foreach($tblheaders as $th) {
// print headernames
echo '<th>'.$th.'</th>';
}
echo '</tr>';
... // draw the header data of messages
echo '</table>';
?>
Net_NNTP::getOverviewFormat()
Net_NNTP::getOverviewFormat() – fetch the name of message headers
Synopsis
require_once 'Net/NNTP.php';
array Net_NNTP::getOverviewFormat (
)
Description
Returns the name of message headers, which is provided by every message
Return value
array - list of header names
Note
This function can not be called statically.
See
Example
Using getOverviewFmt()
<?php
...
$tblheaders = $nntp->getOverviewFormat();
// create a table headline
echo '<table>';
echo '<tr>';
foreach($tblheaders as $th) {
// print headernames
echo '<th>'.$th.'</th>';
}
echo '</tr>';
... // draw the header data of messages
echo '</table>';
?>
Net_NNTP::isConnected()
Net_NNTP::isConnected() – check connection status
Synopsis
require_once 'Net/NNTP.php';
boolean Net_NNTP::isConnected (
)
Description
Returns the status of the connection
Return value
boolean - TRUE, if connected
Note
This function can not be called statically.
Example
Using isConnected()
<?php
...
if(PEAR::isError($response)) {
// something goes wrong, check if we are still connected
if($nntp->isConnected()) {
echo "disconnected from newsserver!"
...
}
}
?>
Net_NNTP::last()
Net_NNTP::last() – get highest message number
Synopsis
require_once 'Net/NNTP.php';
integer Net_NNTP::last (
)
Description
Retrieves the highest message number in the current selected newsgroup
Return value
integer - highest message number
Note
since 0.3
This function can not be called statically.
Example
Using last()
<?php
...
$nntp->selectGroup("php.pear.dev");
echo "highest message number: ".$nntp->last();
?>
Net_NNTP::max()
Net_NNTP::max() – get highest message number
Synopsis
require_once 'Net/NNTP.php';
integer Net_NNTP::max (
)
Description
This function is deprecated. That means that future versions of this package may not support it anymore.
Retrieves the highest message number in the current selected newsgroup
Return value
integer - highest message number
Note
This function can not be called statically.
Example
Using max()
<?php
...
$nntp->selectGroup("php.pear.dev");
echo "highest message number: ".$nntp->max();
?>
Net_NNTP::min()
Net_NNTP::min() – get lowest message number
Synopsis
require_once 'Net/NNTP.php';
integer Net_NNTP::min (
)
Description
This function is deprecated. That means that future versions of this package may not support it anymore.
Retrieves the lowest message number in the current selected newsgroup
Return value
integer - lowest message number
Note
This function can not be called statically.
Example
Using min()
<?php
...
$nntp->selectGroup("php.pear.dev");
echo "lowest message number: ".$nntp->min();
?>
Net_NNTP::post()
Net_NNTP::post() – post a message
Synopsis
require_once 'Net/NNTP.php';
string Net_NNTP::post (
string $subject
,
string $newsgroup
,
string $from
,
string $body
,
string $additional
)
Description
Post a message to a news server
Parameter
-
$subject- Subject of the message -
$newsgroup- Post to this newsgroup -
$from- EMail adress of sender -
$body- Body of the message -
$additional- String of headers to add
Return value
string - Server response
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL |
"Not connected"
|
You forgot the set up a connection to a news server or the connection was already again closed. | Open a connection before using post(). Check the connection status before using post(). |
Note
This function can not be called statically.
post() doesn't care about character encoding of subject and body. Make sure to set correct headers, if you are using non ASCII-127 characters.
Example
Using post()
<?php
...
$subject = "Testpost";
$newsgroup = "php.test";
$body = "Le Mardi 12 f=E9vrier 2002, this is a test message using special french chars";
$from = "test@example.com";
$addheader = "Content-Transfer-Encoding: quoted-printable\n".
"Content-Type: text/plain; charset=ISO-8859-1;";
$response = $nntp->post($subject, $newsgroup, $from, $body, $addheader);
...
?>
Net_NNTP::prepareConnection()
Net_NNTP::prepareConnection() – connects to a newsgroup on a newsserver
Synopsis
require_once 'Net/NNTP.php';
boolean Net_NNTP::prepareConnection (
string $nntpserver
,
integer $port = 119
,
integer $newsgroup
,
integer $user
= null
,
integer $pass
= null
,
integer $authmode = PEAR_NNTP_ORIGINAL
)
Description
Connect to a specific newsserver and access the given newsgroup
This function is deprecated. That means that future versions of this package may not support it anymore.
Consider this method deprecated - use Net_NNTP::connectAuthenticated() instead.
Parameter
-
$nntpserver- Name of the newsserver to connect -
$port- Port, where the newsserver listens -
$newsgroup- Newsgroup to access -
$user- Username to authenticate -
$user- Username to authenticate -
$pass- Password to authenticate -
$authmode- Type of authentication, at the moment only PEAR_NNTP_AUTHORIGINAL
Return value
boolean -
TRUE if successful
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL |
"Could not connect to NNTP-server $nntpserver"
or
"Not connected"
|
The connection couldn't be established because
|
Check for server name, the connection to the net and possible firewalls on client or server side |
| NULL | Every other message | This message is directly passed from the news server, in the most cases caused by calling a non existing newsgroup | Check the given newsgroup name |
Note
This function can not be called statically.
This function is deprecated. That means that future versions of this package may not support it anymore.
Fetching data with a connection created with prepareConnection() is faster then a created connection with connect()
See
Net_NNTP::quit(), Net_NNTP::connect()
Example
Using prepareConnection()
<?php
require_once "Net/NNTP.php";
$nntp = new Net_NNTP;
$ret = $nntp->connect("news.php.net", 119, "php.pear.dev");
if( PEAR::isError($ret)) {
// handle error
} else {
// success
}
?>
Net_NNTP::quit()
Net_NNTP::quit() – disconnect from a newsserver
Synopsis
require_once 'Net/NNTP.php';
void Net_NNTP::quit (
)
Description
Close connection to a newsserver
Note
This function can not be called statically.
See
Net_NNTP::selectGroup()
Net_NNTP::selectGroup() – select a newsgroup
Synopsis
require_once 'Net/NNTP.php';
array Net_NNTP::selectGroup (
string $newsgroup
)
Description
Selects a specific newsgroup on the news server
Parameter
-
string
$newsgroup- Name of the newsgroup to access
Return value
array - If the newsgroup exists an array
containing the message number of the first
(array key: ['first'])
and the last message id (array key: ['last'])
or a PEAR_Error, if fail.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article | Check the article ID or if your are still connected to the server ( Net_NNTP::isConnected()) |
Note
This function can not be called statically.
See
Net_NNTP::connect() , Net_NNTP::getGroups()
Example
Using selectGroup()
<?php
...
$ret = $nntp->connect("news.php.net");
if( PEAR::isError($ret)) {
// handle error
} else {
// success
$data = $nntp->selectGroup("php.pear.dev");
// Print the count of articles
echo "Count: ", $data['last'] - $data['first'];
}
?>
Net_NNTP::setDebug()
Net_NNTP::setDebug() – setting debug mode
Synopsis
require_once 'Net/NNTP.php';
void Net_NNTP::setDebug (
boolean $on
= true
)
Description
Enables or disables debug mode for Net_NNTP
Parameter
-
boolean $on- TRUE = debug on, FALSE = debug off
Note
This function can not be called statically.
Net_NNTP::splitHeaders()
Net_NNTP::splitHeaders() – fetch message headers into in array
Synopsis
require_once 'Net/NNTP.php';
array Net_NNTP::splitHeaders (
string $articleId
)
Description
Returns all avaible header lines of a specified message of the current selected newsgroup into an array
Parameter
-
string
$articleId- Message-ID or Message number
Return value
array - if message exists the headers
as array or a PEAR_Error, if fail.
The array is an associative array with the header names as key.
Throws
| Error code | Error message | Reason | Solution |
|---|---|---|---|
| NULL | Different error messages | The messages are directly passed from the news server, in the most cases caused by calling a non existing article | Check the article ID or if your are still connected to the server ( Net_NNTP::isConnected()) |
Note
This function can not be called statically.
See
Net_NNTP::getHeaders() , Net_NNTP::getBody() , Net_NNTP::getOverview()
Example
Using splitHeaders()
<?php
...
$headers = $nntp->splitHeaders($msg_id);
if( PEAR::isError($headers)) {
// handle error
} else {
// success - print all headers line
foreach($headers as $headerName => $headerValue) {
echo $headerName.': '.$headerValue.'<br>';
}
}
?>
Net_NNTP_Header
This module is EXPERIMENTAL. That means that the behaviour of these functions, these function names, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this module at your own risk.
This package is not documented yet.
Net_NNTP_Message
This module is EXPERIMENTAL. That means that the behaviour of these functions, these function names, in concreto ANYTHING documented here can change in a future release of this package WITHOUT NOTICE. Be warned, and use this module at your own risk.
This package is not documented yet.
Net_NNTP_Protocol_Client
Low level NNTP client implementation.
This package is not documented yet.
Constants
Constants – predefined constants
NET_NNTP_PROTOCOL_CLIENT_DEFAULT_HOST
default NNTP hostname: localhost
NET_NNTP_PROTOCOL_CLIENT_DEFAULT_PORT
default NNTP port: 119