Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F154831
Fork_of_P1137_futures.php
No One
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
hach-que
May 14 2014, 10:48 PM
2014-05-14 22:48:24 (UTC+0)
Size
961 B
Referenced Files
None
Subscribers
None
Fork_of_P1137_futures.php
View Options
#!/usr/bin/env php
<?php
$root
=
dirname
(
dirname
(
dirname
(
__FILE__
)));
require_once
$root
.
'/scripts/__init_script__.php'
;
$number_of_tasks
=
10
;
$number_wait
=
array
(
5
,
5
,
5
,
5
,
1
,
1
,
1
,
1
,
1
,
1
);
$process_wait
=
array
(
3
,
3
,
3
,
3
,
3
,
0
,
0
,
0
,
0
,
0
);
$futures
=
array
();
for
(
$ii
=
0
;
$ii
<
$number_of_tasks
;
$ii
++)
{
$amount
=
$number_wait
[
$ii
];
echo
"sleep "
.
$amount
.
"
\n
"
;
$futures
[
$ii
]
=
new
ExecFuture
(
'sleep %d'
,
$amount
);
}
echo
"[T = "
.
t
().
"] Starting 10 tasks.
\n
"
;
foreach
(
Futures
(
$futures
)->
limit
(
4
)
as
$ii
=>
$future
)
{
if
(
$process_wait
[
$ii
]
>
0
)
{
echo
"wait "
.
$process_wait
[
$ii
].
"
\n
"
;
$st
=
microtime
(
true
);
while
(
microtime
(
true
)
-
$st
<
$process_wait
[
$ii
])
{
sleep
(
microtime
(
true
)
-
$st
);
}
}
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
);
}
File Metadata
Details
Attached
Mime Type
text/plain; charset=utf-8
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/iy/ff/drgpuer2u44ttcvq
Default Alt Text
Fork_of_P1137_futures.php (961 B)
Attached To
Mode
P1140 Fork of P1137 futures.php
Attached
Detach File
Event Timeline
Log In to Comment