Last active
June 1, 2016 06:29
-
-
Save basz/f804eeb73e0f8edfc43ffa9b82d1addd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env php | |
| <?php | |
| $pdo = new PDO("mysql:host=127.0.0.1;dbname=plhw_application_api_development", 'plhwapi_dev', 'xxxxxxxxxxx'); | |
| $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); | |
| print memory_get_usage() . PHP_EOL; | |
| $uresult = $pdo->query("SELECT * FROM event_stream event_stream ORDER BY created_at ASC, version ASC"); | |
| print memory_get_usage() . PHP_EOL; | |
| //outputs | |
| $ ./bin/test.php | |
| 364584 | |
| 329469336 | |
| // |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $sql = "SELECT * FROM event_stream event_stream ORDER BY created_at ASC, version ASC"; | |
| $pdo = new PDO("mysql:host=127.0.0.1;dbname=plhw_application_api_development", 'plhwapi_dev', 'xxxxxxxxxxx', []); | |
| $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); | |
| function generator($pdo, $sql) | |
| { | |
| $stmt = $pdo->prepare($sql); | |
| $stmt->execute(); | |
| while ($rs = $stmt->fetch(\PDO::FETCH_OBJ)) { | |
| yield $rs; | |
| } | |
| } | |
| print memory_get_usage() . PHP_EOL; | |
| $result = generator($pdo, $sql); | |
| print memory_get_usage() . PHP_EOL; | |
| foreach ($result as $row) { | |
| } | |
| print memory_get_usage() . PHP_EOL; | |
| //outputs | |
| $ ./bin/test.php | |
| 365424 | |
| 369936 | |
| 370288 | |
| function generator($pdo, $sql) | |
| { | |
| $stmt = $pdo->prepare($sql); | |
| $stmt->execute(); | |
| print memory_get_usage() . PHP_EOL; // <-- add this line | |
| while ($rs = $stmt->fetch(\PDO::FETCH_OBJ)) { | |
| yield $rs; | |
| } | |
| } | |
| print memory_get_usage() . PHP_EOL; | |
| $result = generator($pdo, $sql); | |
| print memory_get_usage() . PHP_EOL; | |
| foreach ($result as $row) { | |
| } | |
| print memory_get_usage() . PHP_EOL; | |
| $ ./bin/test.php | |
| 362608 | |
| 367120 | |
| 329471936 | |
| 367472 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $sql = "SELECT * FROM event_stream event_stream ORDER BY created_at ASC, version ASC"; | |
| $pdo = new PDO("mysql:host=127.0.0.1;dbname=plhw_application_api_development", 'plhwapi_dev', 'xxxxxxxxxxx', []); | |
| $pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); | |
| print memory_get_usage() . PHP_EOL; | |
| $stmt = $pdo->prepare($sql); | |
| $stmt->execute(); | |
| print memory_get_usage() . PHP_EOL; | |
| while ($rs = $stmt->fetch(\PDO::FETCH_OBJ)) { | |
| } | |
| print memory_get_usage() . PHP_EOL; | |
| //outputs | |
| $ ./bin/test.php | |
| 364520 | |
| 329469272 | |
| 329469272 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment