Skip to content

Instantly share code, notes, and snippets.

@dshafik
Last active December 12, 2015 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dshafik/4705432 to your computer and use it in GitHub Desktop.
Save dshafik/4705432 to your computer and use it in GitHub Desktop.
<?php
date_default_timezone_set("America/New_York");
function gen() {
$i = 0;
while (true) {
file_put_contents("./log",
date("Y-m-d H:i:s") .' '.
(yield $i++) . ' ' .
PHP_EOL
, FILE_APPEND);
}
}
$gen = gen();
var_dump($gen->send("First Call")); // 1
sleep(3);
var_dump($gen->send("Second Call")); // 2
2013-02-04 02:35:46 First Call
2013-02-04 02:35:46 Second Call
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment