file() function crashing a script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kaspar
Forum Newbie
Posts: 4
Joined: Sun Sep 25, 2005 3:49 pm

file() function crashing a script

Post by kaspar »

Has anyone ever seen this happen?

I'm moving a site to a different host. A script that used the file() function
just dies when it gets to this line:

$data = file($file);

The script stops and the status bar of the browser says: Done

Checking for what the script should have done reveals that it did nothing.
It just died.

PHP version (4.3.11) is exactly the same as the other server was using.
The Zend stuff displayed by phpinfo() is a little different.

On the site where everything works, I see this:

This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies with
Zend Extension Manager v1.0.6, Copyright (c) 2003-2004, by Zend
Technologies with Zend Optimizer v2.5.7, Copyright (c) 1998-2004, by
Zend Technologies

On the one where it doesn't work, I see this:

This program makes use of the Zend Scripting Language Engine:
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies with the
ionCube PHP Loader v2.5, Copyright (c) 2002-2004, by ionCube Ltd.

Does this matter? Or is it something else?

Please help; I'm desperately trying to meet a deadline (this Friday!)


Thanks in advance
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

Make sure your error checking is set to E_ALL, for starters.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

as mentioned erlier, what errors are displayed?
kaspar
Forum Newbie
Posts: 4
Joined: Sun Sep 25, 2005 3:49 pm

file() error

Post by kaspar »

Hi Jason,

The way this host configured PHP when they compiled it, no errors
are displayed - ever. So E_ALL didn't help a bit. But I finally located
the error_log. I found this:

PHP Fatal error: Allowed memory size of 33554432 bytes exhausted
(tried to allocate 12 bytes)

It's apparently happening because a memory_limit of 32MB was compiled
into PHP. This line:

$data = file($file);

causes the error when the size of $file is too large. I was able to get
the script to run mormally when $file was around 1MB but I need to
process much larger files with the script. Some are as large as 7MB.

Unless I can get PHP re-compiled with memory_limit off, I don't know
of anything that will fix the problem. I'd do it myself if I could find a
way to log in to a shell. It's not that hard to do - if you've spent as
many years in a Linux environment as I have.

I guess I just don't like Plesk - it seems to be web admin for dummies.

Jcart wrote:as mentioned erlier, what errors are displayed?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you could process the file line by line manually, so long as you didn't keep all the data in memory too long.
kaspar
Forum Newbie
Posts: 4
Joined: Sun Sep 25, 2005 3:49 pm

Thanks, feyd

Post by kaspar »

That's the workaround I've been using. But these files have very short lines
(7 characters) and there are between 100,000 and 1,000,000 lines per file.
Pretty slow to process because of all those disk accesses. After a while, the
output screen just hangs, even though processing is still going on. You can't
tell when the script has finished; it just stops putting anything on the screen.

When it's running properly it puts a dot on the screen for every 1000 lines
and reports a count every 50,000 lines. It should output the total number
of line processed when it finishes. Around 40 of these files need to be
processed once a month. I don't want it to be an all-day job.
feyd wrote:you could process the file line by line manually, so long as you didn't keep all the data in memory too long.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

sounds like your server needs to either be upgraded or optimized...
kaspar
Forum Newbie
Posts: 4
Joined: Sun Sep 25, 2005 3:49 pm

Right, feyd

Post by kaspar »

I'll have to rewrite the Makefile and rebuild PHP from the source code.

( Or else pay the hosting company to do it...)
feyd wrote:sounds like your server needs to either be upgraded or optimized...
Post Reply