2011-03-01 6 views
0

크론 작업을 실행하는 데 문제가 있습니다.크론 작업에서 XML을로드하는 방법

<?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'; 
?> 

내가 브라우저에서이 파일을 실행하면 잘 작동하지만, 크론이 실행될 때 나는 아래의 오류 가지고 : 여기

내 코드입니다

<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 

답변

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 

로컬 환경에서 테스트하는 경우는 (노트북 아마도) 다음 웹 서버를 다시 시작하십시오 나는 좀 더 많은 피드백을주고 그것을 조금 수정 . 그 외에는 무엇이 잘못되었는지 미안합니다.

+0

네, 고마워요, 제가 이것을 분류했습니다. 문제가 호스팅 계정에있었습니다. 내 cron 작업이 실행될 때 유지 관리 모드에있었습니다. 그게 왜 내가 오류가있어. 시간 내 주셔서 감사합니다. – Avinash