Jump to content

Recommended Posts

I am using this command and it seems the machine go to freeze and doesnt output anything only keep the page busy. The file i am trying to search and print size is 76.79Mb.

 

log24 file data:

8888888888888

aaaaaaaaaaaaaaaaaaa

bbbbbbbbbbbbbbbbbbbbb ---

2222222222222

aaaaabbbbbbbbbbbbbb

aaaaaaaaaaaaacccccc ---

 

<?php

// This is the virtual FTP drive files.
$v_sfilelist="z:\\usr2\\log\\log24"

// Open the file read only
if ($lines = @fopen($v_sfilelist, "r") ){
// Loop the whole file until it end
while(!feof($lines) ){
        // Take only 100 lines to quick test
$buffer = $buffer . fgets($lines,100);
}
// Close the file its done.
fclose($lines);	
}

// From the buffer, make array of real needs
$split = explode('---', $buffer);
// clear the memory
unset($buffer);

foreach ($split as $line_num => $line) {  
// print it
echo $line;
}

?>

Link to comment
https://forums.phpfreaks.com/topic/130060-solved-fopen-problem/
Share on other sites

The posted code contains a fatal parse error due to a missing ; on the end of line 4, so it is not executing anyway.

 

If that is just a typo in the post (I wish people would not introduce errors in code they post that must be solved before the real problem can be found), the size of the file is probably triggering a memory related error. Have you checked your web server error log file for errors?

Link to comment
https://forums.phpfreaks.com/topic/130060-solved-fopen-problem/#findComment-674368
Share on other sites

How we do this ? one case is solved but another case it is not.

 

Code 1: works because 1024

 

<?php

error_reporting(E_ALL);
// This is the virtual FTP drive files.
/**
* log24 contain lines like this.
* file size 73.5mb.
* aaaaaaaaaaaaaaaaaaaaaaaa
* bbbbbbbbbbbbbbbbbbbbbbbb ---
* aaaaaaaaaaaaaaaaaaaaaaaa
* bbbbbbbbbbbbbbbbbbbbbbbb
* cccccccccccccccccccccccc ---
*
*/
$v_sfilelist="d:\\log24";

// Open the file read only
if ($lines = @fopen($v_sfilelist, "r") ){
// Loop the whole file until it end
while(!feof($lines) ){
   // Take only 100 lines to quick test
   $buffer = fread($lines, 1024);
}
// Close the file its done.
fclose($lines);  
}

// From the buffer, make array of real needs
$split = explode('---', $buffer);
// clear the memory
unset($buffer);

foreach ($split as $line_num => $line) { 
// print it
echo $line . '<br/>';
}

?>

 

Code 2: hang machine

 

<?php

error_reporting(E_ALL);
// This is the virtual FTP drive files.
/**
* log24 contain lines like this.
* file size 73.5mb.
* aaaaaaaaaaaaaaaaaaaaaaaa
* bbbbbbbbbbbbbbbbbbbbbbbb ---
* aaaaaaaaaaaaaaaaaaaaaaaa
* bbbbbbbbbbbbbbbbbbbbbbbb
* cccccccccccccccccccccccc ---
*
*/
$v_sfilelist="d:\\log24";

// Open the file read only
if ($lines = @fopen($v_sfilelist, "r") ){
// Loop the whole file until it end
while(!feof($lines) ){
   // Take only 100 lines to quick test
   $buffer = fread($lines);
}
// Close the file its done.
fclose($lines);  
}

// From the buffer, make array of real needs
$split = explode('---', $buffer);
// clear the memory
unset($buffer);

foreach ($split as $line_num => $line) { 
// print it
echo $line . '<br/>';
}

?>

 

(edited by kenrbnsn to add


tags)

Link to comment
https://forums.phpfreaks.com/topic/130060-solved-fopen-problem/#findComment-674447
Share on other sites

[suggested use]: Large file handlers, please use this formula. The chunks method is speed processing of large files much faster then not using it. Output is also possible to speed by using the header contents, but in anyway my handle for 80 to 100mb files are much faster with following codes.

 

<?php

/** 
* Error report if any
*/
error_reporting(E_ALL);
// manualy assign the RAM reserve
// ini_set("memory_limit","16M");

/**
* File settings
* 
*/
$filepath="d:\\log24";
// File size
$total = filesize($filepath);
// Memory use
$blocksize = (2 << 20); //2M chunks
// Download
$sent = 0;
// File pointer
$handle = fopen($filepath, "r");

/**
* Assign the page with content
* header('Content-type: '.$content_type);
*/
header('Content-Disposition: attachment; filename=log24');
header('Content-length: '.$total);

// Now we need to loop through the file and echo out chunks of file data
// Processing is faster
while($sent < $total){
$buffer =  fread($handle, $blocksize);
$sent += $blocksize;
}

// Output is standard
// It depends now what exactly i should use
$split = explode('---', $buffer);
echo $split[3];

exit(0);

?>

Link to comment
https://forums.phpfreaks.com/topic/130060-solved-fopen-problem/#findComment-674477
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.