Ensure flow control commands don't remove internal breakpoints set by real breakpoints
[hiphop-php.git] / hphp / doc / threading
blob32802a63d5d5cfa1add72c53c164bda7dc7dd351
2 <h2> Multi-Tasking and Multi-Threading Support</h2>
4 To perform parallel execution in PHP without forking a new process, you may
5 take advantage of one of these new facilities:
7 1. Pagelet Server
9 The pagelet server is similar to a CURL call to localhost. Look for "Pagelet
10 Server" in compiled program's options for how to set it up. The new pagelet
11 server functions work like this:
13   // This starts a pagelet server thread to process the URL just as if
14   // it's a new web request with specified headers and post data.
15   // The request method would be GET if the post data is empty.
16   $task = <b>pagelet_server_task_start</b>($url, $headers, $post_data);
17   // Main thread can now do extra work while pagelet server is processing.
18   ...
19   // Optionally make this non-blocking call any time to check status.
20   $status = <b>pagelet_server_task_status</b>($task);
21   ...
22   // Finally, we make a blocking call to wait for pagelet server's result,
23   // which is the entire output of the web page, with response headers and
24   // status code. The status code is set to 0 if a flushed partial response is
25   // successfully returned and the pagelet server is still active.
26   //
27   // A timeout of 0 is interpreted as an infinite timeout. The status code is
28   // set to -1 in the event of a timeout.
29   $headers = array(); $code = 0;
30   $result = <b>pagelet_server_task_result</b>($task, $headers, $code,
31                                               $timeout_ms);
33 2. Xbox Tasks
35 The xbox task system is designed to provide cross-box messaging as described in
36 "server.xbox_server" documentation. The xbox task system may also be used to
37 execute a task on the local machine in a separate thread. Here is an example:
39   // We start an xbox task by sending to localhost a message.
40   $task = <b>xbox_task_start</b>($message);
41   // Main thread can now do extra work while xbox task is processing.
42   ...
43   // Optionally make this non-blocking call any time to check status.
44   $status = <b>xbox_task_status</b>($task);
45   ...
46   // Finally, we make a blocking call to check message processing returns.
47   $ret = null;
48   $code = <b>xbox_task_result</b>($task, $timeout_ms, $ret);
50 On the message processing side, one has to implement a PHP function like this:
52   function <b>xbox_process_message</b>($msg) {
53     ...
54     return $ret;
55   }
57 Note that an xbox thread starts its execution with its own global state without
58 sharing anything with main thread, other than $msg and $ret that are passed
59 between these threads at enter and exit points.