shamuntoha Posted October 26, 2008 Share Posted October 26, 2008 Trying to cut a large file in parts and print it , but why its now pringing? i am using phpDesigner 2008. <?php /** * Large file devide in small part * */ //error_reporting(E_ALL); // Take the whole file as string $f1 = file_get_contents("log24"); // Reserve the size as len $total = strlen($f1); // Cut in pieces $part1 = substr($f1, 0, $total/2 ); // $part2 = substr($f1, $total/2, $total); // Part 1 - Array the needs $ex1 = explode("---", $part1); // Part 2 - Array the needs $ex2 = explode("---", $part2); echo $ex1[0]; echo $ex2[0]; exit(0); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/ Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 why are you trying to cut it in half? Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675055 Share on other sites More sharing options...
shamuntoha Posted October 26, 2008 Author Share Posted October 26, 2008 This is the error getting while trying outside phpDesigner 2008. Fatal error: Allowed memory size of 103809024 bytes exhausted (tried to allocate 588 bytes) in D:\xampp\htdocs\jony\index.php on line 8 <?php error_reporting(E_ALL); ini_set("memory_limit","99M"); $f1 = file_get_contents("d:\\log24"); $total = strlen($f1); //$deel1 = substr($f1, 0, $total/2 ); //$deel2 = substr($f1, $total/2, $total ); $ex = explode("---", $f1); echo $ex[0]; exit(0); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675063 Share on other sites More sharing options...
genericnumber1 Posted October 26, 2008 Share Posted October 26, 2008 the file is too large, and you're loading every single piece into a string. I'd advise changing the way you handle it, but if it's just a one-time-run script (for testing or something) you could always further increase the memory limit. Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675066 Share on other sites More sharing options...
shamuntoha Posted October 26, 2008 Author Share Posted October 26, 2008 Once i need to open it and split it by '---' to an array item. Output result is less, so its not risk for freezing the browser. But explode is the main requirement for this file. ??? log24 contain: /*/**/*sadfdsf*adsfewe343242342343243324324adfdsfdsfdsfsdfdsfsdfsfsasfsfd --- /*/**/*sa3333333333333333333333333333342342343243324324adfdsfdsfdsfsdfdsfsdfsfsasfsfd --- /*/**/*sadfdsf*adsfewe343242342343243324324adfdsfdsfdsfsdfdsfsdfsfsasfsfd --- /*/**/*sadfdsf*adsfewe343244556566666666666fdsfdsfsdfdsfsdfsfsasfsfd --- Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675071 Share on other sites More sharing options...
DeanWhitehouse Posted October 26, 2008 Share Posted October 26, 2008 If i understand you right why not just do it manually? Split the file yourself Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675073 Share on other sites More sharing options...
shamuntoha Posted October 26, 2008 Author Share Posted October 26, 2008 Yes split in parts is also not helping showing the allocation error. Fatal error: Allowed memory size of 83886080 bytes exhausted (tried to allocate 15358622 bytes) in D:\xampp\htdocs\jony\index.php on line 6 <?php error_reporting(E_ALL); ini_set("memory_limit","80M"); $f1 = file_get_contents("d:\\log24"); $total = strlen($f1); $part1 = substr($f1, 0, $total/5 ); //$part 2= substr($f1, $total/2, $total ); $ex = explode("---", $part1); echo $ex[0]; exit(0); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675075 Share on other sites More sharing options...
DeanWhitehouse Posted October 26, 2008 Share Posted October 26, 2008 It doesn't seem like you are reading what people have wrote Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675078 Share on other sites More sharing options...
shamuntoha Posted October 26, 2008 Author Share Posted October 26, 2008 Did you mean to do following ? 3 different method try. new 2 as following. Handle 1: Notice: Undefined variable: line in D:\xampp\htdocs\jony\index.php on line 6 Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 33292271 bytes) in D:\xampp\htdocs\jony\index.php on line 6 <?php error_reporting(E_ALL); //ini_set("memory_limit","M"); $file = fopen("d:\\log24", "r"); while ( !feof($file) ) { $line = $line . fgets($file); } $ex = explode('---', $line); echo $ex[0]; exit(0); ?> Handle 2: Notice: Undefined variable: line in D:\xampp\htdocs\jony\index.php on line 10 Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 31457281 bytes) in D:\xampp\htdocs\jony\index.php on line 10 <?php error_reporting(E_ALL); //ini_set("memory_limit","M"); $send = 0; $chunks = (2 << 20); $total = filesize("d:\\log24"); $file = fopen("d:\\log24", "r"); while ( $send < $total ) { $line = $line . fread($file, $chunks); $send += $chunks; } $ex = explode('---', $line); echo $ex[0]; exit(0); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675083 Share on other sites More sharing options...
DeanWhitehouse Posted October 26, 2008 Share Posted October 26, 2008 If i understand you right why not just do it manually? Split the file yourself Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675085 Share on other sites More sharing options...
shamuntoha Posted October 26, 2008 Author Share Posted October 26, 2008 What do you mean by this ? can you explain? "split the file yourself" Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675089 Share on other sites More sharing options...
DeanWhitehouse Posted October 26, 2008 Share Posted October 26, 2008 Are you serious? Why do you not just split the file/files yourself instead of using code? Its not like i am saying anything complex Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675090 Share on other sites More sharing options...
Andy-H Posted October 26, 2008 Share Posted October 26, 2008 PMSL!!! Open the file in your browser, find the half way mark, copy the first half, paste it somewhere, copy the second half, paste it somewhere then you have one file split in to 2 files MANUALLY... Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675157 Share on other sites More sharing options...
shamuntoha Posted October 26, 2008 Author Share Posted October 26, 2008 Thanks, i came to this code, which is much faster. <?php /** * If any errors * - Large file handle * - 100mb to 200mb * - unix grep use, tail etc */ error_reporting(E_ALL); // File total size $fsize = filesize("d:\\log24"); // for ini_set $fsize += 32 * 100 * 1024; // ini_set("memory_limit", $fsize . "M"); // Set memory to use ini_set("memory_limit","90M"); // Start and Download move $send = 0; // Set the chunk $chunk = (2 << 20); // Create large array. $buffer = array(); // File resource $ex = fopen("d:\\log24", "rb"); // Attempts to try $i=0; // Loop to get data as binary safe while($send <= $fsize){ $buffer[$i] = explode('---', fread($ex,$chunk) ); $send += $chunk; $i++; } // Close resource fclose($ex); // Clear send unset ($send); // Output the data foreach($buffer as $key=>$value){ echo $key; } // Clear ram unset($buffer); // Exit exit(0); ?> Quote Link to comment https://forums.phpfreaks.com/topic/130175-explode-fail/#findComment-675165 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.