기본적으로 rss 피드를 읽고 사용자 정의 태그를 추가하여 XML을 만들려고합니다. 나는 내 코드가 들어있는 함수를 만들었고 이제는 다른 rss URL로 함수를 여러 번 호출하려고한다. 각 호출은 다른 .xml 파일을 생성합니다.
DOMDocument를 사용하여 rss 및 simple_html_dom을로드하고 구문 분석하여 각 rss 항목의 링크를로드하고 구문 분석하여 html에서 일부 내용을 가져옵니다.
여기 내 코드의 간단한 예입니다PHP가 이전 함수가 완료 될 때까지 대기합니다.
<?php
include('simple_html_dom.php');
load_custom_rss('http://www.somesite.com/rssfeed/articles', 'articles.xml');
load_custom_rss('http://www.somesite.com/rssfeed/jobs', 'jobs.xml');
load_custom_rss('http://www.somesite.com/rssfeed/press', 'press.xml');
//up to 20 similar function calls here...
function load_custom_rss($link, $filename){
$doc = new DOMDocument();
$doc->load($link);
$newDoc = new DOMDocument('1.0', 'UTF-8');
$rss = $newDoc->createElement('rss');
$channel = $newDoc->createElement('channel');
$newDoc->appendChild($rss);
$rss->appendChild($channel);
foreach ($doc->getElementsByTagName('item') as $node) {
//here is some code to read items from rss xml/write them to new xml document.
//Code missing for simplicity
//Next lines used to get some elements from the html of the item's link
$html = new simple_html_dom();
html->load_file($node->getElementsByTagName('link')->item(0)->nodeValue);
$ret = $html->find('#imgId');
}
$newDoc->formatOutput = true;
$fh = fopen($filename, 'w') or die("can't open file");
fwrite($fh, $newDoc->saveXML());
fclose($fh);
unset($doc);
//unset ALL variables and objects created in this function...
//........
}//function end
?>
내 문제는 3 또는 기능 아파치의 4 호출이 심각한 오류를 발생 후 수 있도록 함수의 각 호출로, 메모리의 상당한 양을 소비한다는 것입니다 함수에서 생성 된 모든 변수와 객체를 설정 해제하더라도 스크립트는 memory_limit보다 큰 메모리를 소비합니다. 함수 호출을 1 또는 2로 줄이면 모든 것이 잘 동작합니다.
작동 방식이 있습니까? 각 함수 호출이 시작하기 전에 이전에 끝날 때까지 기다렸지 만 어떻게 할 수 있습니까?
누군가가 도와 줄 수 있기를 바랍니다. 사전에 감사합니다.
아파치에서 실행해야합니까, 아니면 명령 줄에서 실행할 수 있습니까? 후자의 경우 시간과 메모리에 대한 엄격한 제한이 없습니다. –