forked from nikic/ditaio
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to pass context to
file_uri
, various bug fixes found whe…
…n adding `fileUri.php` example
- Loading branch information
1 parent
6cb195a
commit 8fb6868
Showing
5 changed files
with
144 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
include 'vendor/autoload.php'; | ||
|
||
/** | ||
* Converted example of https://github.com/jimmysong/asyncio-examples from: | ||
* @see https://youtu.be/qfY2cqjJMdw | ||
*/ | ||
function get_statuses($websites) | ||
{ | ||
$statuses = ['200' => 0, '400' => 0, '405' => 0]; | ||
$tasks = []; | ||
foreach ($websites as $website) { | ||
$tasks[] = yield \away(\get_website_status($website)); | ||
} | ||
|
||
$taskStatus = yield \gather($tasks); | ||
foreach ($taskStatus as $id => $status) { | ||
if (!$status) | ||
$statuses[$status] = 0; | ||
else | ||
$statuses[$status] += 1; | ||
} | ||
|
||
return \json_encode($statuses); | ||
} | ||
|
||
function get_website_status($url) | ||
{ | ||
$id = yield \get_task(); | ||
$fd = yield \file_uri($url); | ||
$status = \file_meta($fd, 'status'); | ||
yield \file_close($fd); | ||
//[$meta, $status, $retry] = yield \head_uri($url); | ||
print "task: $id, url: $url code: $status" . EOL; | ||
return yield $status; | ||
} | ||
|
||
function lapse() | ||
{ | ||
$i = 0; | ||
while (true) { | ||
echo '.'; | ||
$i++; | ||
if ($i == 800) { | ||
yield \shutdown(); | ||
} | ||
|
||
yield; | ||
} | ||
} | ||
|
||
function main() | ||
{ | ||
yield \away(\lapse()); | ||
$websites = yield \file_file(__DIR__ . \DS . 'list_many.txt'); | ||
if ($websites !== false) { | ||
$t0 = \microtime(true); | ||
$data = yield get_statuses($websites); | ||
$t1 = \microtime(true); | ||
print $data . EOL; | ||
print("getting website statuses took " . (float) ($t1 - $t0) . " seconds"); | ||
} | ||
} | ||
|
||
\coroutine_run(\main()); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
https://facebook.com/ | ||
https://twitter.com/ | ||
https://google.com/ | ||
https://youtube.com/ | ||
https://linkedin.com/ | ||
https://instagram.com/ | ||
https://pinterest.com/ | ||
https://blogspot.com/ | ||
https://wordpress.com/ | ||
https://apple.com/ | ||
https://tumblr.com/ | ||
https://vimeo.com/ | ||
https://godaddy.com/ | ||
https://yahoo.com/ | ||
https://flickr.com/ | ||
https://microsoft.com/ | ||
https://dell.com/ | ||
https://nytimes.com/ | ||
https://blogger.com/ | ||
https://soundcloud.com/ | ||
https://digg.com/ | ||
https://feedburner.com/ | ||
https://stumbleupon.com/ | ||
https://github.com/ | ||
https://parallels.com/ | ||
https://cnn.com/ | ||
https://paypal.com/ | ||
https://creativecommons.org/ | ||
https://imdb.com/ | ||
https://huffingtonpost.com/ | ||
https://espn.com/ |