Solved

PHP: fopen and large file

Posted on 2009-07-02
8
313 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
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 5

Expert Comment

by:mallcore
Comment Utility
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
Comment Utility
@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
Comment Utility
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
 
LVL 5

Accepted Solution

by:
mallcore earned 500 total points
Comment Utility
Just noticed you are reading the file binary
ini_set('max_execution_time', '10000');
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 36

Expert Comment

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

Expert Comment

by:Loganathan Natarajan
Comment Utility
consider to read chunk and open it.,

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

Expert Comment

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

0
 

Author Comment

by:tomcupr
Comment Utility
@bportlock it's tab delimited data
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
The viewer will learn how to dynamically set the form action using jQuery.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now