3
This seems to have been an issue last night with one of our sites running 2.0.7.
It would be pretty easy to hack the headlines update script to first ping sites before attempting to load a feed to prevent having the server wait for a timeout.
In the file /modules/xoopsheadline/class/headlinerenderer.php, replacing this code (around line 60):
function updateCache()
{
if (!$fp = fopen($this->_hl->getVar('headline_rssurl'), 'r')) {
$this->_setErrors('Could not open file: '.$this->_hl->getVar('headline_rssurl'));
return false;
}
<etc>
with the following (UNTESTED):
function pingDomain( $url ) {
preg_match_all( '/http://([w.]{2,})/i', $url, $match );
$url = $match[1][0];
exec( "ping -n 4 $url", $list );
foreach ( $list as $l ) {
if ( preg_match( '/unknown host/i', $l ) )
return false;
if ( preg_match( '/100% packet loss/i', $l ) )
return false;
}
return true;
}
function updateCache()
{
$url = $this->_hl->getVar('headline_rssurl');
if ( !pingDomain( $url ) ) {
$this->_setErrors('Could not access domain: '.$url);
return false;
}
if (!$fp = fopen($url, 'r')) {
$this->_setErrors('Could not open file: '.$url);
return false;
}
Of course, the pingDomain() method could be refactored out as a general-purpose utility function, since it could be useful to other modules as well.
I think this would greatly speed up the headlines module on failing feeds, since the fopen() wouldn't have to wait for the timeout.
The above code is not a universal solution. The format of return results on the ping command could be extended to other systems than Windows/Linux if applicable. It also depends on the availability of shell commands in the running PHP version. I'm not aware of a built-in ping command in PHP.
Please comment.
Eric
[EDIT: modified some errors in code, added UNTESTED
]