Solved

PHP: fopen and large file

Posted on 2009-07-02
8
348 Views
Last Modified: 2012-05-07
Hi,

I'm trying to open large (ish) text file using fopen and then read it line by line to create mysql queries. The size of the file is 264.8 MB. The script times out every time despite increasing max_execution_time to 1000. Are there any other variables that I should be looking at or is 1000 simply to low?

Thank you in advance!
$handle = fopen($file, "rb");
 
		if ($handle)
		{
			$line = fgets($handle);

Open in new window

0
Comment
Question by:tomcupr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 5

Expert Comment

by:mallcore
ID: 24764478
There is a function called
file($file) or
file_get_contents($file)

The first one puts the entire file into array, the other one reads the file and puts it into a string. In my opinion its easier.
0
 

Author Comment

by:tomcupr
ID: 24764541
@mallcore: will it solve my problem though? I am not looking for an easier but working solution and I'm not too sure that 264 MB string or array would work...
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24764650
Increasing 264M with  max_execution_time won't help. you should see in php.ini file and keep it less than 128M and try it out...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Accepted Solution

by:
mallcore earned 500 total points
ID: 24764653
Just noticed you are reading the file binary
ini_set('max_execution_time', '10000');
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24764657
also check, set_time_limit from php.ini and work on.
0
 
LVL 36

Expert Comment

by:Loganathan Natarajan
ID: 24764673
consider to read chunk and open it.,

ref. http://php.net/manual/en/function.readfile.php
0
 
LVL 34

Expert Comment

by:Beverley Portlock
ID: 24764856
What is in the file? Is it CSV data or SQL queries or something else?

0
 

Author Comment

by:tomcupr
ID: 24764862
@bportlock it's tab delimited data
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question