A Brief Introduction to Multi-Threading in PHP
- Foreword
- Execution
- Sharing
- Synchronization
- Pitfalls
| <?php | |
| use \parallel\{Runtime, Future, Channel, Events}; | |
| /* usage php crawler.php [http://example.com] [workers=8] [limit=500] */ | |
| $page = $argv[1] ?: "https://blog.krakjoe.ninja"; # start crawling this page | |
| $workers = $argv[2] ?: 8; # start this number of threads | |
| $limit = $argv[3] ?: 500; # stop at this number of unique pages | |
| $timeout = $argv[4] ?: 3; # socket timeout for producers |
This is a sample PHP script to retrieve the access token from Service Account of Google without using googleapis.
<?php
$private_key = "-----BEGIN PRIVATE KEY-----\n###-----END PRIVATE KEY-----\n"; // private_key of JSON file retrieved by creating Service Account