PHP: fopen and large file


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

Who is Participating?
mallcoreConnect With a Mentor Commented:
Just noticed you are reading the file binary
ini_set('max_execution_time', '10000');
There is a function called
file($file) or

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.
tomcuprAuthor 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...
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Loganathan NatarajanLAMP DeveloperCommented:
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...
Loganathan NatarajanLAMP DeveloperCommented:
also check, set_time_limit from php.ini and work on.
Loganathan NatarajanLAMP DeveloperCommented:
consider to read chunk and open it.,

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

tomcuprAuthor Commented:
@bportlock it's tab delimited data
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.