Last active
July 3, 2018 19:11
-
-
Save garyrojas/55180ae995a5bc03f567441a2e72f3d6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Task extends Threaded | |
{ | |
public $response; | |
public function scraping() | |
{ | |
$content = file_get_contents('https://www.amazon.com'); | |
preg_match('~<title>(.+)</title>~', $content, $matches); | |
$this->response = $matches[1]; | |
} | |
} | |
$task = new Task; | |
$thread = new class($task) extends Thread { | |
private $task; | |
public function __construct(Threaded $task) | |
{ | |
$this->task = $task; | |
} | |
public function run() | |
{ | |
$this->task->scraping(); | |
} | |
}; | |
$thread->start() && $thread->join(); | |
var_dump($task->response); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment