0

cronジョブの実行に問題があります。

これが私のコードです:

<?php
    $doc = new DOMDocument();
    $doc->load( 'http://www.all-news.in/feed' );

    $items = $doc->getElementsByTagName( "item" );

    mysql_connect('host','username','pass');
    mysql_select_db('dbname');

    $i=0;
    foreach( $items as $itemname )
    {
        // Here Business logic for Inserting the data
    }   

    echo $i.' Imported';
?>

このファイルをブラウザで実行すると正常に動作しますが、cronを実行すると、次のエラーが発生します。

<br />
<b>Warning</b>:  DOMDocument::load(http://www.all-news.in/feed) [<a href='domdocument.load'>domdocument.load</a>]: failed to open stream: Connection timed out in <b>/home/content/98/7509598/html/amz/social-bookmark.in/cron_jobs/all_news.php</b> on line <b>4</b><br />
<br />
<b>Warning</b>:  DOMDocument::load() [<a href='domdocument.load'>domdocument.load</a>]: I/O warning : failed to load external entity &quot;http://www.all-news.in/feed&quot; in <b>/home/content/98/7509598/html/amz/social-bookmark.in/cron_jobs/all_news.php</b> on line <b>4</b><br />
0 Imported
4

1 に答える 1

1

コードを試しましたが、エラーは発生していません。フィードバックを追加するために少し変更しました。

error_reporting(E_ALL);
$doc = new DOMDocument();
$doc->load( 'http://www.all-news.in/feed' );

$items = $doc->getElementsByTagName( "item" );
var_dump($items);
// mysql_connect('host','username','pass');
// mysql_select_db('dbname');

$i=0;
foreach( $items as $itemname )
{
    var_dump( $itemname ); $i++;
    // Here Business logic for Inserting the data
}   

echo $i.' Imported';

これは私に与えます:

object(DOMNodeList)#2 (0) { } object(DOMElement)#3 (0) { } object(DOMElement)#5 (0) { } object(DOMElement)#3 (0) { } object(DOMElement)#5 (0) { } object(DOMElement)#3 (0) { } object(DOMElement)#5 (0) { } object(DOMElement)#3 (0) { } object(DOMElement)#5 (0) { } object(DOMElement)#3 (0) { } object(DOMElement)#5 (0) { } 10 Imported

ローカル環境(おそらくラップトップ)でテストしている場合は、Webサーバーを再起動してみてください。それ以外は何が悪いのかわかりません申し訳ありません。

于 2011-03-01T18:05:26.030 に答える