Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- define("SQL_HOST", "localhost");
- define("SQL_USER", "db_user");
- define("SQL_PASS", "db_pass");
- define("SQL_DB", "db_db");
- class sql {
- public static $connection;
- public static function __callstatic($method, $args){
- if (self::$connection) {
- return call_user_func_array(array(self::$connection, $method), $args);
- } else {
- self::$connection = new mysqli(SQL_HOST, SQL_USER, SQL_PASS, SQL_DB);
- if (self::$connection)
- return call_user_func_array(array(self::$connection, $method), $args);
- }
- }
- }
- class apiSEND extends Thread {
- public $data;
- public function __construct($arg) {
- $this->arg = $arg;
- }
- public function run() {
- if ($this->arg) {
- $sleep = mt_rand(1, 10);
- printf('%s: %s -start -sleeps %d' . "\n", date("g:i:sa"), $this->arg, $sleep);
- echo "<br>";
- printf("%s is Thread #%lu\n", __CLASS__, $this->getThreadId());
- echo "<br>";
- sleep($sleep);
- printf('%s: %s -finish' . "\n", date("g:i:sa"), $this->arg);
- echo "<br>";
- }
- }
- } // end class
- /*
- this comes with array data from the database to start the processes that must be performed in multi-thread
- */
- $fb_loadCronPostSYS['dados'] = fb_loadCronPostSYS();
- $stack = array();
- //Iniciate Multiple Thread
- foreach ($fb_loadCronPostSYS['dados'] as $i) {
- $stack[] = new apiSEND($i, $facebook);
- }
- // Start The Threads
- foreach ($stack as $t) {
- $t->start();
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement