Databases Reference
In-Depth Information
if
(
$from
<
$to
) {
storm_emit
(
array
(
"
$from
"
));
$task_ids
=
read_msg
();
$from
++
;
}
else
{
sleep
(
1
);
}
}
storm_sync
();
}
?>
And for your bolt:
<?
php
function
isPrime
(
$number
) {
if
(
$number
<
2
) {
return
false
;
}
if
(
$number
==
2
) {
return
true
;
}
for
(
$i
=
2
;
$i
<=
$number
-
1
;
$i
++
) {
if
(
$number
%
$i
==
0
) {
return
false
;
}
}
return
true
;
}
function
read_msg
() {
$msg
=
""
;
while
(
true
) {
$l
=
fgets
(
STDIN
);
$line
=
substr
(
$l
,
0
,
-
1
);
if
(
$line
==
"end"
) {
break
;
}
$msg
=
"
$msg$line
\n
"
;
}
return
substr
(
$msg
,
0
,
-
1
);
}
function
write_line
(
$line
) {
echo
(
"
$line
\n
"
);
}
function
storm_emit
(
$tuple
) {
$msg
=
array
(
"command"
=>
"emit"
,
"tuple"
=>
$tuple
);
storm_send
(
$msg
);
}
function
storm_send
(
$json
) {
write_line
(
json_encode
(
$json
));
write_line
(
"end"
);
}