Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Paste
P1137
futures.php
Active
Public
Actions
Authored by
epriestley
on May 14 2014, 1:58 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Flag For Later
Award Token
Tags
None
Referenced Files
F154665: futures.php
May 14 2014, 1:58 PM
2014-05-14 13:58:08 (UTC+0)
Subscribers
None
#!/usr/bin/env php
<?php
$root
=
dirname
(
dirname
(
dirname
(
__FILE__
)));
require_once
$root
.
'/scripts/__init_script__.php'
;
$number_of_tasks
=
$argv
[
1
];
$seconds_per_task
=
$argv
[
2
];
$seconds_of_processing
=
$argv
[
3
];
$futures
=
array
();
for
(
$ii
=
0
;
$ii
<
$number_of_tasks
;
$ii
++)
{
$futures
[]
=
new
ExecFuture
(
'sleep %d'
,
$seconds_per_task
);
}
echo
"[T = "
.
t
().
"] Starting {$number_of_tasks} tasks, "
.
"which will take {$seconds_per_task} each, "
.
"and require {$seconds_of_processing} seconds to process.
\n
"
;
foreach
(
Futures
(
$futures
)
as
$future
)
{
sleep
(
$seconds_of_processing
);
echo
"[T = "
.
t
().
"] Completed a task.
\n
"
;
}
echo
"[T = "
.
t
().
"] Done.
\n
"
;
function
t
()
{
static
$start
;
if
(!
$start
)
{
$start
=
microtime
(
true
);
}
return
sprintf
(
'%.1f'
,
microtime
(
true
)
-
$start
);
}
Event Timeline
epriestley
edited the content of this paste.
(Show Details)
May 14 2014, 1:58 PM
2014-05-14 13:58:08 (UTC+0)
epriestley
changed the title of this paste from untitled to
futures.php
.
epriestley
updated the paste's language from
autodetect
to
autodetect
.
Log In to Comment