Jump to content


Photo

PHP Script shows blank screen when reading big txt files.


  • Please log in to reply
4 replies to this topic

#1 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 16 June 2006 - 05:15 PM

I have a script which is required to read certain text files and output results. The problem is the script shows up a blank screen when the Text file is very big... i am talking about text files which have about 40000 lines.

right now, this is my code

$contents = file_get_contents($file);
$title =  preg_replace('/^(?!TITLE).*?(?:\n|$)/m','',$contents);
$title = substr($title ,6, 44);

The script fails to output $title for huge files, if the files are small, the script shows up.

what do i do?

#2 jvrothjr

jvrothjr
  • Members
  • PipPipPip
  • Advanced Member
  • 300 posts
  • LocationOhio

Posted 16 June 2006 - 05:26 PM

Sounds like a time-out issue.

php.ini file

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30 ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)

; Maximum time (in secondes) for connect timeout. -1 means no limit
mysql.connect_timeout = 60

also could be your resources set on your my.ini file
If you understand everything you know nothing!

http://rcchjr.awardspace.com/

#3 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 16 June 2006 - 05:29 PM

[!--quoteo(post=384667:date=Jun 16 2006, 12:26 PM:name=jvrothjr)--][div class=\'quotetop\']QUOTE(jvrothjr @ Jun 16 2006, 12:26 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Sounds like a time-out issue.

php.ini file

;;;;;;;;;;;;;;;;;;;
; Resource Limits ;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30 ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)

; Maximum time (in secondes) for connect timeout. -1 means no limit
mysql.connect_timeout = 60

also could be your resources set on your my.ini file
[/quote]

yeah i just tried changing it to 99, still shows a blank screen...


#4 nogray

nogray
  • Members
  • PipPipPip
  • Advanced Member
  • 930 posts
  • LocationSan Francisco CA

Posted 16 June 2006 - 05:33 PM

This is just a guess, but maybe the server doesn't have enough room to open the big file at once,

Try to use fopen, fread, fclose to open the file in pieces instead of one big chunk.

This way, the variables don't need a lot of memory to run.

NoGray.com


#5 vidyashankara

vidyashankara
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 16 June 2006 - 05:44 PM

[!--quoteo(post=384674:date=Jun 16 2006, 12:33 PM:name=nogray)--][div class=\'quotetop\']QUOTE(nogray @ Jun 16 2006, 12:33 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
This is just a guess, but maybe the server doesn't have enough room to open the big file at once,

Try to use fopen, fread, fclose to open the file in pieces instead of one big chunk.

This way, the variables don't need a lot of memory to run.
[/quote]

there were 8 php.ini files on my system, changed it all. the server has ike 2 gb memory. a 2 mb file should be a problem.
i am running it on my system itself. i am trying to read it in chunks.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users