/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Memory Allocation Error

I used to much somewhere ?

Errors on line 34

[code][B]Fatal error[/B]: Allowed memory size of 67108864 bytes exhausted (tried to allocate 66846704 bytes) in [B]/home/content/o/m/n/omnisistem/html/xml/feed.php[/B] on line [B]34[/code]

[/B]

Someone mind helping me find out how to prevent this pitfall?
Thanks guys.

[code=php]
<?php

$narray = array();
$t = “ttt”;
$i = 0;

$payload = “t<?xml version=”1.0″ encoding=”utf-8″ standalone=”yes”?>r”;
$payload .= “t<rss version=”2.0″ xmlns:media=”http://search.yahoo.com/mrss/”r”;
$payload .= “txmlns:atom=”http://www.w3.org/2005/Atom”>r”;
$payload .= “t<channel>r”;

$path = “../images/media/tradeshows/thumb/”;
$dir_handle = @opendir($path) or die(“Unable to open $path”);

while ( false !== ($file = readdir($dir_handle))) {
if(is_dir($file)) {
continue;

} else if( strpos($file, ‘.gif’, 1) || strpos($file, ‘.jpg’, 1) ) {
$narray[$i] = $file;
$i++;
}

}

sort($narray);
$item = “rtt<item>”;
$item .= “r$t<title>”;
$item .= “</title>r”;

for ( $loop_start = 0; isset($narray[$loop_start]);
$loopstart++) {

$item .= “$t<link>explode/$narray[$loop_start]</link>r”;
$item .= “$t<media:thumbnail url=”$base/thumb/$narray[$loop_start]” />r”;
$item .= “$t<media:content url=”$base/explode/$narray[$loop_start]” />r”;

}

closedir($dir_handle);

$item .= “tt</item>r”;
$payload .= $item;

$payload .= “rt</channel>rt</rss>”;

$file = $_SERVER[‘DOCUMENT_ROOT’] . “/xml/feed.xml”;
$fh = fopen($file, ‘w’) or die(“can’t open file”);
fwrite($fh, $payload);
fclose($fh);

echo “Payload written to: $file”;
?>
[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Mar 22.2010 — Why aren't you using SimpleXML to build the xml?
Copy linkTweet thisAlerts:
@ehimeauthorMar 22.2010 — I was just doing a quick one time hack. I'm not proficient

enough with SimpleXML to use it without a lot of for-thought.

If you don't mind helping I'll rewrite it in SXML though. I just

need to grab the contents of a dir, sort by name (reverse?),

and write to file. Easy enough (evidently :shiftyeyes: )

Sorry Crit, but SimpleXML isn't so simple....
Copy linkTweet thisAlerts:
@NogDogMar 22.2010 — You have an infinite loop here:
[code=php]
for ( $loop_start = 0; isset($narray[$loop_start]);
$loopstart++) {
[/code]

[b]$loopstart++[/b] needs to be [b]$loop_start++[/b] to match the initially defined counter variable. Better would probably be to use a foreach() loop, instead.
Copy linkTweet thisAlerts:
@ehimeauthorMar 22.2010 — Still ironing out a few bugs, but like always Nog, your answer came through.
×

Success!

Help @ehime spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...