Freelancers Network
 
skill list top cap
Homepage
Join the Freelancer's Network
Update your details
Find a freelancer
Post a project
Find a project
Projects Archive
Post a job
Find a job
Jobs Archive
See Dan's Pages
See Andy's Pages
Link to this site
Resources
Join/Leave Forum
Forum Messages
+Additions+ Adverts
Advertising
Contact Us
Subscribe to our newsletter - enter your email address and hit return
Freelancers.net is owned and operated by Andy Stowell and Dan Winchester
skill list end cap
guru web hostcom

Find me again on Freelancers.net

Re: FN-FORUM: php xml_parser

date posted 15th April 2008 14:19

On 15/04/2008 15:34, Steven wrote:
>
> Hi Guys,
>
> I'm really pulling my hair out here. I am using the following class to
> parse a number of xml files that I am retrieving from a remote server.
> Each xml file has 1000 row tags E.G. ... etc. I can parse the
> first xml file fine, no problems however when I try to get the next xml
> file. I get the following error (I have set php.ini to use 48MB of memory).
>
> *Fatal error*: Allowed memory size of 50331648 bytes exhausted (tried to
> allocate 32 bytes) in
> */var/www/rainbow/public_html/php/classes/merlin.class.php* on line *139
>
> in each loop i use the following code.
>
> while(glob("*.xml") as $filename) {
> $xml_data = $this->getXmlData($filename);
> $xml_parser = new xml();
> $xml_parser->parse($xml_data);
> $dom = $xml_parser->dom;
> * }
>
> If I change the code and move the * $xml_parser = new xml(); line to
> before the while loop, I do not get the fatal error, however the
> contents of $dom remain as the previous loop xml contents.
>
> Does any one have any ideas to over come this?
>
> Steve
> *

Could you set $dom to null at the start of the while loop?

Increase the amount of memory available in the php ini?

Try set the memory available dynamically in the code based on the xml
file size - I do something similar when dealing with jpegs, I'm sure it
could be adapted (the original code probably came from php.net):

private static function setMemoryForImage( $filename )
{
$imageInfo = getimagesize($filename);
$MB = 1048576; // number of bytes in 1M
$K64 = 65536; // number of bytes in 64K
$TWEAKFACTOR = 16; // Or whatever works for you
$memoryNeeded = round( ( $imageInfo[0] * $imageInfo[1]
* $imageInfo['bits']
* $imageInfo['channels'] / 8
+ $K64
) * $TWEAKFACTOR
);
//ini_get('memory_limit') only works if compiled with
"--enable-memory-limit" also
//Default memory limit is 8MB so well stick with that.
//To find out what yours is, view your php.ini file.
$memoryLimit = 8 * $MB;
if (function_exists('memory_get_usage') &&
memory_get_usage() + $memoryNeeded > $memoryLimit)
{
$newLimit = $memoryLimitMB + ceil( ( memory_get_usage()
+ $memoryNeeded
- $memoryLimit
) / $MB
);
ini_set( 'memory_limit', $newLimit . 'M' );
return true;
}
else
{
return false;
}
}


Martin



Messages by Day
April 30th 2008
April 29th 2008
April 28th 2008
April 27th 2008
April 26th 2008
April 25th 2008
April 24th 2008
April 23rd 2008
April 22nd 2008
April 21st 2008
April 20th 2008
April 19th 2008
April 18th 2008
April 17th 2008
April 16th 2008
April 15th 2008
April 14th 2008
April 13th 2008
April 12th 2008
April 11th 2008
April 10th 2008
April 9th 2008
April 8th 2008
April 7th 2008
April 6th 2008
April 5th 2008
April 4th 2008
April 3rd 2008
April 2nd 2008
April 1st 2008


Messages by Month
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
March 2008
February 2008
January 2008


Messages by Year
2008
2007
2006
2005
2004
2003
2002
2001
2000