Wait for a Thread to Finish in PHP
pthreads waiting thread function to finish before move on
<?php
class TestThread extends Thread
{
//
function __construct($parameters) {
$this->reverse = $parameters;
}
public function run() {
try {
sleep(20);
// Connecting to mysql database
$cn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
INSERT INTO DEVICE_SESSION_ADDRESS (X, Y, Z)
VALUES (1,2,3)
} catch (Exception $ex) {
//do stuffs
}
}
}
?>
function from a Rest api method:
function test ($response) {
require_once 'TestThread.php';
$rev = new TestThread($response);
$rev->start();
}