lavinpj1
05-27-2006, 01:31 AM
I have made the following to put the last 5 news entries on a site's RSS feed into a database...
<?php
$content = file_get_contents("http://flyinghamster.com/feed/");
$pattern = '@(<title>).*?(?=</title>)@';
preg_match_all($pattern, $content, $title);
$pattern = '@(<link>).*?(?=</link>)@';
preg_match_all($pattern, $content, $link);
$pattern = '@(<pubDate>).*?(?=\+[0-9]{4}</pubDate>)@';
preg_match_all($pattern, $content, $date);
mysql_connect('localhost', 'xxx', 'xxx');
mysql_select_db('xxx');
$pattern = '@<[^<>]+>@';
for ($i = 1; $i <= 5; $i++) {
$tit = preg_replace($pattern, '', $title[0][$i]);
$dat = preg_replace($pattern, '', $date[0][$i]);
$lin = preg_replace($pattern, '', $link[0][$i]);
mysql_query("INSERT INTO `hamster` SET `Title`='$tit', `Date`='$dat', `Link`='$lin'");
}
unset($content);
unset($tit);
unset($dat);
unset($lin);
unset($title);
unset($link);
unset($date);
mysql_close();
?>
This is run on a cron job every 1 min and I loaded it a few hours ago. I then tried to convert some pictures to thumbnails on my gallery, a task which php normally manages just fine with. This returned an out of memory error. I had to raise PHPs memory limit to 32mb before it would work.
Anyone have any suggestions as to why this could be, and how to prevent it?
~Phil~
<?php
$content = file_get_contents("http://flyinghamster.com/feed/");
$pattern = '@(<title>).*?(?=</title>)@';
preg_match_all($pattern, $content, $title);
$pattern = '@(<link>).*?(?=</link>)@';
preg_match_all($pattern, $content, $link);
$pattern = '@(<pubDate>).*?(?=\+[0-9]{4}</pubDate>)@';
preg_match_all($pattern, $content, $date);
mysql_connect('localhost', 'xxx', 'xxx');
mysql_select_db('xxx');
$pattern = '@<[^<>]+>@';
for ($i = 1; $i <= 5; $i++) {
$tit = preg_replace($pattern, '', $title[0][$i]);
$dat = preg_replace($pattern, '', $date[0][$i]);
$lin = preg_replace($pattern, '', $link[0][$i]);
mysql_query("INSERT INTO `hamster` SET `Title`='$tit', `Date`='$dat', `Link`='$lin'");
}
unset($content);
unset($tit);
unset($dat);
unset($lin);
unset($title);
unset($link);
unset($date);
mysql_close();
?>
This is run on a cron job every 1 min and I loaded it a few hours ago. I then tried to convert some pictures to thumbnails on my gallery, a task which php normally manages just fine with. This returned an out of memory error. I had to raise PHPs memory limit to 32mb before it would work.
Anyone have any suggestions as to why this could be, and how to prevent it?
~Phil~