fwrite and memory error

This is a discussion on fwrite and memory error within the PHP Language forums, part of the PHP Programming Forums category; I'm trying to save an XML file sent to me in ZIP format. Here is the code: if($XMLFile=...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-07-2005
Bob Bedford
 
Posts: n/a
Default fwrite and memory error

I'm trying to save an XML file sent to me in ZIP format.
Here is the code:
if($XMLFile=fopen($XMLPath.strtoupper(substr($file ,0,strlen($file)-4)).".XML",'w'))
if(fwrite($XMLFile,zip_entry_read($zip_entry,zip_e ntry_filesize($zip_entry)))){

here is the error:
Allowed memory size of 8388608 bytes exhausted (....)

The problem occurs on the "fwrite" function.

This appens when the XML file is very large (seems more than the 8mb limit).

I can't change this size server side, as my ISP doesn't allow me to do that.

Hot to fix the problem script side ???

Bob



Reply With Quote
  #2 (permalink)  
Old 02-07-2005
Rasmus Rimestad
 
Posts: n/a
Default Re: fwrite and memory error

Bob Bedford wrote:

>if($XMLFile=fopen($XMLPath.strtoupper(substr($fil e,0,strlen($file)-4)).".XML",'w'))


>if(fwrite($XMLFile,zip_entry_read($zip_entry,zip_ entry_filesize($zip_entry)))){



Try not writing the entire zip at once, but do it a bit at a time so
there never has to exist a variable that is larger than 8 MB.

--
Rasmus Rimestad, webprogrammer
http://www.rimestad.no/en

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Reply With Quote
  #3 (permalink)  
Old 02-07-2005
Bob Bedford
 
Posts: n/a
Default Re: fwrite and memory error

"Rasmus Rimestad" <""rasmus\"@rimestad.n0sp@am.no"> a écrit dans le message
de news: 42075446_2@127.0.0.1...
> Bob Bedford wrote:
>
> >if($XMLFile=fopen($XMLPath.strtoupper(substr($fil e,0,strlen($file)-4)).".XML",'w'))

>
> >if(fwrite($XMLFile,zip_entry_read($zip_entry,zip_ entry_filesize($zip_entry)))){

>
>
> Try not writing the entire zip at once, but do it a bit at a time so there
> never has to exist a variable that is larger than 8 MB.


I've been looking around without finding a way to do so. Could you please
tell me how ?

Bob


Reply With Quote
  #4 (permalink)  
Old 02-09-2005
Rasmus Rimestad
 
Posts: n/a
Default Re: fwrite and memory error

The manual says that if you do not specify the size you want to read in
zip_entry_read then it will read 1024 bytes. Have you tried something
like this?

while($size < zip_entry_filesize($zip_entry)) {
fwrite($XMLFile,zip_entry_read($zip_entry));
$size += 1024;
}

Rasmus Rimestad
Web databases at a price you can live with -> http://www.rimestad.no
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:12 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0