[284] | 1 | <?php |
---|
| 2 | /***********************************************************************************\ |
---|
| 3 | * eGroupWare - Contacts Center * |
---|
| 4 | * http://www.egroupware.org * |
---|
| 5 | * Written by: * |
---|
| 6 | * - Brian W. Bosh from Multi-threading strategies in PHP at * |
---|
| 7 | * http://www.alternateinterior.com/2007/05/multi-threading-strategies-in-php.html * |
---|
| 8 | * Adapted by: * |
---|
| 9 | * - Mário César Kolling <mario.kolling@serpro.gov.br> * |
---|
| 10 | * ----------------------------------------------------------------------------------* |
---|
| 11 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 12 | * under the terms of the GNU General Public License as published by the * |
---|
| 13 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 14 | * option) any later version. * |
---|
| 15 | \***********************************************************************************/ |
---|
| 16 | |
---|
| 17 | set_time_limit (0); |
---|
| 18 | require 'ThreadUtility.inc.php'; |
---|
| 19 | |
---|
| 20 | /* |
---|
| 21 | * A class that is extended by the new php process and deals with communication at the new php process side |
---|
| 22 | */ |
---|
| 23 | |
---|
| 24 | class ThreadInstance { |
---|
| 25 | var $stdin; |
---|
| 26 | var $stdout; |
---|
| 27 | |
---|
| 28 | function setup() { |
---|
| 29 | $this->stdin = fopen ("php://stdin", "r"); |
---|
| 30 | $this->stderr = fopen ("php://stderr", "w"); |
---|
| 31 | stream_set_blocking ($this->stdin, false); |
---|
| 32 | } |
---|
| 33 | function getCommand() { |
---|
| 34 | return $this->getLine(true); |
---|
| 35 | } |
---|
| 36 | function response ($status, $data) { |
---|
| 37 | response ($status, $data); |
---|
| 38 | } |
---|
| 39 | function getLine ($wait = false) { |
---|
| 40 | if ($wait) { |
---|
| 41 | $buffer = ""; |
---|
| 42 | while (!strlen($buffer)) { |
---|
| 43 | $buffer .= fgets ($this->stdin, 1024); |
---|
| 44 | } |
---|
| 45 | } else { |
---|
| 46 | $buffer = fgets ($this->stdin, 1024); |
---|
| 47 | } |
---|
| 48 | return trim($buffer); |
---|
| 49 | } |
---|
| 50 | function debug ($text) { |
---|
| 51 | fwrite ($this->stderr, $text); |
---|
| 52 | } |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | ?> |
---|