Weird PHP Error

He has: 1,380 posts

Joined: Feb 2002

Has anyone ever seen this before?

<strong>Fatal error</strong>:  Out of memory (allocated 131334144) (tried to allocate 16 bytes) in <strong>/usr/pkg/share/httpd/htdocs/includes/cubico/rss_gen.php</strong> on line <strong>13</strong>
'

I have modified the php.ini file before, and it's set to allow 120s of script runtime, 120s of system queries, and 128MB of memory usage per instance... so this really doesn't have anything to do with the server config, I think.

It's appearing in a script I wrote (that will run as a CRON job) that creates/updates different RSS feeds across the site... the error it refers to is more or less the following

<?php
$feed
= fopen('/location/of/file.xml', 'r+');
while (!
feof($feed)) {
  
// do stuff
}
?>

"Line 13" corresponds directly to the while statement... but that's almost verbatim from the php.net docs on fopen... And then sometimes it refers to things within the while loop, but that's less often.

So something's wrong. The files exist, they're all chmod'd to 777, accessible by the PHP script, PHP is configured for even more memory usage than by default, I cleaned up all typographical/syntax errors...

Any thoughts? You can even see it in action for yourself (I put it on a test page until I get it working.. then it disappears into a non-WWW cron job)
http://www.cubico.com/test.php

Thanks for any help...

[As a side note, if you poke around the site... don't blame me. This is not my company, but rather the person who pays my rent. I do all of the backend work, and only some of the UI... but alot of what I do in the UI gets erased by my boss who seems to things using random colors is a good idea, and that dynamic things like a lightbox video player is terrible. Oh, and did I mention he's computer illiterate, but still has the nerve to tell me what's best? Anyways... I do the things you don't see. "Don't hate the player, hate the game"]

pr0gr4mm3r's picture

He has: 1,502 posts

Joined: Sep 2006

How are you reading the file? Are you reading entire files to variables? 128mb of memory is way to much for a PHP script to use unless you're doing major on-the-fly images or something.

My guess is that you have an infinite loop somewhere that reads something until it uses up too much memory. Would you be willing to post the entire script?

He has: 1,380 posts

Joined: Feb 2002

Well the idea is that it does read a file back into memory, yes, but the problem with that is that the files are empty. I just created "main.xml" and all the other files as empty, saved them, and put them on the server.

...As I write that, I have a thought. Would it be possibly that there isn't any EOF since it's just a blank file, without contents? Could that really be the problem? hahaha wow

He has: 1,380 posts

Joined: Feb 2002

As it turns out, it was looping infinitely. But even more importantly, I decided it would take less system resources to just read from a MySQL table than to read from a flat file... so I scrapped the whole fread() sequence anyways.

Just thought I'd let you know. Thanks for being my spark... hahah

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.