Solved

PHP: fopen and large file

Posted on 2009-07-02
8
322 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
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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
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.

919 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

16 Experts available now in Live!

Get 1:1 Help Now