Advertisement
Guest User

SourceForge - pthreads - php

a guest
Feb 27th, 2014
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. <?php
  2. define("SQL_HOST", "localhost");
  3. define("SQL_USER", "db_user");
  4. define("SQL_PASS", "db_pass");
  5. define("SQL_DB", "db_db");
  6.  
  7. class sql {
  8.     public static $connection;
  9.    
  10.     public static function __callstatic($method, $args){
  11.         if (self::$connection) {
  12.             return call_user_func_array(array(self::$connection, $method), $args);
  13.     } else {
  14.         self::$connection = new mysqli(SQL_HOST, SQL_USER, SQL_PASS, SQL_DB);
  15.         if (self::$connection)
  16.         return call_user_func_array(array(self::$connection, $method), $args);
  17.     }
  18.     }
  19. }
  20.  
  21.  
  22. class apiSEND extends Thread {
  23.     public $data;
  24.    
  25.     public function __construct($arg) {
  26.             $this->arg = $arg;
  27.     }
  28.  
  29.     public function run() {
  30.         if ($this->arg) {
  31.             $sleep = mt_rand(1, 10);
  32.             printf('%s: %s  -start -sleeps %d' . "\n", date("g:i:sa"), $this->arg, $sleep);
  33.             echo "<br>";
  34.             printf("%s is Thread #%lu\n", __CLASS__, $this->getThreadId());
  35.             echo "<br>";
  36.             sleep($sleep);
  37.             printf('%s: %s  -finish' . "\n", date("g:i:sa"), $this->arg);
  38.             echo "<br>";           
  39.         }
  40.     }  
  41.  
  42.    
  43. } // end class
  44.    
  45.     /*
  46.     this comes with array data from the database to start the processes that must be performed in multi-thread
  47.     */
  48.     $fb_loadCronPostSYS['dados'] = fb_loadCronPostSYS();
  49.        
  50.     $stack = array();
  51.    
  52.     //Iniciate Multiple Thread
  53.     foreach ($fb_loadCronPostSYS['dados'] as $i) {
  54.         $stack[] = new apiSEND($i, $facebook);
  55.     }
  56.        
  57.     // Start The Threads
  58.     foreach ($stack as $t) {
  59.         $t->start();
  60.     }
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement