Guest User

Untitled

a guest
Apr 20th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. class MTDaemon{
  2. var $threads = 4;
  3. var $idlesleeptime = 3;
  4.  
  5. var $run=true;
  6. var $slot=0;
  7. function __construct($threads = null, $idlesleeptime = null){
  8. if ($threads) {
  9. $this->threads=$threads;
  10. }
  11. if ($idlesleeptime) {
  12. $this->idlesleeptime=$idlesleeptime;
  13. }
  14. }
  15.  
  16. function handle(){
  17. while($this->run){
  18.  
  19. if ($this->slot>=$this->threads) {
  20. pcntl_wait(&$status);
  21. $this->slot--;
  22. }
  23. $next=$this->getNext($this->slot);
  24. if ($next==null) {
  25. continue;
  26. }
  27. if ($this->run==false) {
  28. break;
  29. }
  30. if(pcntl_fork()==0){
  31. $this->run($next,$this->slot);
  32. exit;
  33. }
  34. $this->slot++;
  35. }
  36. }
  37.  
  38. function run($next,$slot){
  39.  
  40. }
  41. function getNext($slot){
  42.  
  43. }
  44.  
  45. }
Add Comment
Please, Sign In to add comment