Advertisement
Eeems

irc.class.php

May 21st, 2011
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.84 KB | None | 0 0
  1. <?php
  2.  
  3.     class irc{
  4.  
  5.         function __construct($se = array()){
  6.  
  7.             foreach($se as $s){
  8.  
  9.                 if(!isset($s['channels'])){
  10.  
  11.                     $s['channels'] = array();
  12.  
  13.                 }
  14.  
  15.                 $this->addServer($s['server'],$s['port'],$s['nick'],$s['name'],$s['channels']);
  16.  
  17.             }
  18.  
  19.             $this->wait();
  20.  
  21.         }
  22.  
  23.         function wait(){
  24.  
  25.             foreach($this->servers as $pid){
  26.  
  27.                 pcntl_waitpid($pid,$status);
  28.  
  29.             }
  30.  
  31.         }
  32.  
  33.         function addServer($se,$po,$ni,$na,$cha = array()){
  34.  
  35.             if(!$this->child){
  36.  
  37.                 $pid = pcntl_fork();
  38.  
  39.                 $this->servers[]  = $pid;
  40.  
  41.                 if ($pid == -1) {
  42.  
  43.                     die('could not fork');
  44.  
  45.                 } else if ($pid) {
  46.  
  47.                 } else {
  48.  
  49.                     $this->child = true;
  50.  
  51.                     // we are the child
  52.  
  53.                     $s = new server($se,$po,$ni,$na,$cha);
  54.  
  55.                     $s->recieve();
  56.  
  57.                 }
  58.  
  59.             }
  60.  
  61.         }
  62.  
  63.         private $servers;
  64.  
  65.         private $child = false;
  66.  
  67.     }
  68.  
  69. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement