We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

PHP: fopen and large file

tomcupr
tomcupr asked
on
Medium Priority
392 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

Comment
Watch Question

Commented:
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.

Author

Commented:
@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...
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
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...
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
also check, set_time_limit from php.ini and work on.
Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
consider to read chunk and open it.,

ref. http://php.net/manual/en/function.readfile.php
CERTIFIED EXPERT

Commented:
What is in the file? Is it CSV data or SQL queries or something else?

Author

Commented:
@bportlock it's tab delimited data
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.