473,854 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP read large file line by line?

hi,

how to read a large php file line by line?

fread can't?

thanks.

Oct 13 '06 #1
5 72606
Hmm howa <ho******@gmail .comwrote:
hi,

how to read a large php file line by line?

fgets

--
~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~ ~~~~~~~~~~~~
Ikciu | gg: 718845 | yahoo: ikciu_irsa | www: www.e-irsa.pl

2be || !2be $this =mysql_query();
Oct 13 '06 #2

$file_array = file($file_name );

foreach ($file_array as $line_number =$line)
{
// Handle the line
}

See: http://us3.php.net/manual/en/function.file.php
howa wrote:
hi,

how to read a large php file line by line?

fread can't?

thanks.
Oct 13 '06 #3
ZabMilenko wrote:
>
$file_array = file($file_name );

foreach ($file_array as $line_number =$line)
{
// Handle the line
}

See: http://us3.php.net/manual/en/function.file.php
howa wrote:
>hi,

how to read a large php file line by line?

fread can't?

thanks.
The problem with your solution is it reads the entire file into the
array. Note he said LARGE FILE. This could very quickly run him out of
memory.

Ikciu has the correct answer. fgets() is the way to go.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Oct 13 '06 #4
[ Please don't top-post. Read http://www.caliburn.nl/topposting.html ]

ZabMilenko top-posted (corrected):
howa wrote:
>hi,

how to read a large php file line by line?

fread can't?

thanks.

$file_array = file($file_name );

foreach ($file_array as $line_number =$line)
{
// Handle the line
}

See: http://us3.php.net/manual/en/function.file.php
What if the file is larger than memory_limit (8Mb)?

http://www.php.net/manual/en/ini.cor...i.memory-limit

fgets() is the right answer in this case.

So, instead of coding with file() which works now with a 200K file,
start with fgets and your script will not break when the file grows.

http://www.php.net/fgets

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Oct 13 '06 #5
I would go fgets, this will allow you to control how much of the file
you would like to do, or maybe possibly do it in batches.

On Oct 14, 4:17 am, Pedro Graca <hex...@dodgeit .comwrote:
[ Please don't top-post. Readhttp://www.caliburn.nl/topposting.html]

ZabMilenko top-posted (corrected):
howa wrote:
hi,
how to read a large php file line by line?
fread can't?
thanks.
$file_array = file($file_name );
foreach ($file_array as $line_number =$line)
{
// Handle the line
}
See: http://us3.php.net/manual/en/function.file.phpWhat if the file is larger than memory_limit (8Mb)?

http://www.php.net/manual/en/ini.cor...i.memory-limit

fgets() is the right answer in this case.

So, instead of coding with file() which works now with a 200K file,
start with fgets and your script will not break when the file grows.

http://www.php.net/fgets

--
File not found: (R)esume, (R)etry, (R)erun, (R)eturn, (R)eboot
Oct 15 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
17100
by: Chris | last post by:
Can anybody help. I need to read a txt file backwords line by line. Can anybody help me do this. Thanks Chris
2
12991
by: ohaya | last post by:
Hi, I'm a real newbie, but have been asked to try to fix a problem in one of our JSP pages that is suppose to read in a text file and display it. From my testing thus far, it appears this page is somehow hanging when relatively large file is used. My original intent was to try to just add a check for file size, and error out somehow if the file was "too" large, but in looking at the
6
6565
by: guillaume | last post by:
I have to read and process a large ASCII file containing a mesh : a list of points and triangles. The file is 100 MBytes. I first tried to do it in memory but I think I am running out of memory therefore I decide to use the shelve module to store my points and elements on disks. Despite the fact it is slow ... Any hint ? I think I have the same memory problem but I don't understand why since my aPoint should be removed by the gc.
1
2081
by: Yong Wang | last post by:
Hi, All: I need to read a input file as soucre to process data. Ideally if I can read a line from input file as a list (coloumn separate by white space), reorganize field in a line. Does python has this kind of command ? for example, I read a line has: "IP MAC Date..." as a line from input file, How can I only get MAC ? Thanks, Yong
12
5694
by: Martin Dieringer | last post by:
I am trying to split a file by a fixed string. The file is too large to just read it into a string and split this. I could probably use a lexer but there maybe anything more simple? thanks m.
6
3559
by: Kinbote | last post by:
Hi, I'm trying to make a function that opens a file, reads it in line by line, puts each line into an malloc'd array, and returns the array. I suspect I'm going about it in an atypical fashion, as I'm avoiding the use of fscanf and fgets to read in lines. I don't want to have to specify a temporary char* buffer to read in each line, and then have to concern myself with the (remote) possibility of overflows or with increasing the buffer...
2
1373
by: Sean Davis | last post by:
This should be a relatively simple problem, but I haven't quite got the idea of how to go about it. I have a VERY large file that I would like to load a line at a time, do some manipulations on it, and then make it available to as a file-like object for use as input to a database module (psycopg2) that wants a file-like object (with read and readlines methods). I could write the manipulated file out to disk and then read it back in, but...
2
5462
by: Kevin Ar18 | last post by:
I posted this on the forum, but nobody seems to know the solution: http://python-forum.org/py/viewtopic.php?t=5230 I have a zip file that is several GB in size, and one of the files inside of it is several GB in size. When it comes time to read the 5+GB file from inside the zip file, it fails with the following error: File "...\zipfile.py", line 491, in read bytes = self.fp.read(zinfo.compress_size) OverflowError: long it too large to...
1
1440
by: vaskarbasak | last post by:
Hi All, I have a text file.The file size is very big.I have to read the file from different line number. e.g File test.txt contains 10000000 lines and more.The 1st thread read the file from line 1 to 1000.2 nd thread read the file from line 1100 to 2000.3 rd thread read the file from line 2100 to 3000.. so on. Please help me. Thanks!
0
11031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10685
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10763
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10371
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9518
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
7082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5750
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4563
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4162
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.