Skip to content
This repository has been archived by the owner on Dec 16, 2019. It is now read-only.

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
krakjoe committed Jul 28, 2015
1 parent 7d4e30a commit b97173c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions examples/CallAnyFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
This isn't built in as it's a pretty simple task to achieve for your self
I can't really think of any functions that are labourious enough that you
would want to execute them by themselves in a thread of their own. Maybe
you have functions within your own code that could be called async without
you have functions within your own code that could be called in parallel without
refactoring for multi-threading capabilities ...
I personally think you shouldn't try to make chocolate from cheese and you
would be better of refactoring your code to be multi-threaded ...
But here's an example of how you would achieve such a task:
*/
class Async extends Thread {
class Caller extends Thread {
/**
* Provide a passthrough to call_user_func_array
**/
Expand All @@ -35,7 +35,7 @@ public function run(){
* Static method to create your threads from functions ...
**/
public static function call($method, $params){
$thread = new Async($method, $params);
$thread = new Caller($method, $params);
if($thread->start()){
return $thread;
} /** else throw Nastyness **/
Expand All @@ -55,7 +55,7 @@ public function __toString(){
}

/* here's us calling file_get_contents in a thread of it's own */
$future = Async::call("file_get_contents", array("http://www.php.net"));
$future = Caller::call("file_get_contents", array("http://www.php.net"));
/* here's us counting the bytes out, note, __toString() magic joined so no need to join explicitly */
printf("Got %d bytes from php.net\n", strlen((string)$future));
/* you can reference again as a string because you cached the result, YOU CANNOT JOIN TWICE */
Expand All @@ -65,4 +65,4 @@ public function __toString(){
/* you could also not use a reference to the thread,
if the threads job was to say, log stats and you do not need to know when or how it returns,
then you could just Async::call at the beginning of the request and by the end it would be finished */
?>
?>
4 changes: 2 additions & 2 deletions examples/KeepAliveSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function http_parse_headers($header)
}

/**
* The thread's run() method that runs asynchronously.
* The thread's run() method that runs in parallel.
*
* @link http://www.php.net/manual/en/thread.run.php
*/
Expand Down Expand Up @@ -191,4 +191,4 @@ public function run()
foreach ($workers as $worker) {
$worker->join();
}
}
}
2 changes: 1 addition & 1 deletion examples/stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
/**
* Threaded class
*
* Threaded objects form the basis of pthreads ability to execute user code asynchronously;
* Threaded objects form the basis of pthreads ability to execute user code in parallel;
* they expose and include synchronization methods and various useful interfaces.
*
* Threaded objects, most importantly, provide implicit safety for the programmer;
Expand Down

0 comments on commit b97173c

Please sign in to comment.