Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function getLines($file) {
- $f = fopen($file, 'r');
- if (!$f) throw new Exception();
- while ($line = fgets($f, 1024)) {
- yield strlen($line);
- }
- var_dump($f);
- fclose($f);
- var_dump($f);
- }
- function getLines_res($f) {
- if (!$f) throw new Exception();
- while ($line = fgets($f, 1024)) {
- yield strlen($line);
- }
- }
- function getLines_try($file) {
- $f = fopen($file, 'r');
- if (!$f) throw new Exception();
- try {
- while ($line = fgets($f, 1024)) {
- yield strlen($line);
- }
- } catch (Exception $e) {
- var_dump($f);
- fclose($f);
- var_dump($f);
- }
- var_dump($f);
- fclose($f);
- var_dump($f);
- }
- echo "<pre>";
- @Timer::start();
- foreach(getLines('xml.xml') as $k => $item){
- echo $k.': '.$item."\n";
- if($k>5){
- echo "break\n";
- break;
- }
- }
- echo 'Time: '.@Timer::get();
- echo PHP_EOL.PHP_EOL;
- @Timer::start();
- $f = fopen('xml.xml', 'r');
- foreach(getLines_res($f) as $k => $item){
- echo $k.': '.$item."\n";
- if($k>5){
- echo "break\n";
- fclose($f);
- break;
- }
- }
- echo 'Time: '.@Timer::get();
- echo PHP_EOL.PHP_EOL;
- @Timer::start();
- $gen = getLines_try('xml.xml');
- foreach($gen as $k => $item){
- echo $k.': '.$item."\n";
- if($k>5){
- echo "break\n";
- $gen->throw(new Exception('break and close!'));
- break;
- }
- }
- echo 'Time: '.@Timer::get();
- echo "</pre>";
Advertisement
Add Comment
Please, Sign In to add comment