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
Solved

PHP: fopen and large file

Posted on 2009-07-02
8
340 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
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

765 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