Skip to content

Instantly share code, notes, and snippets.

@garyrojas
Last active July 3, 2018 19:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garyrojas/55180ae995a5bc03f567441a2e72f3d6 to your computer and use it in GitHub Desktop.
Save garyrojas/55180ae995a5bc03f567441a2e72f3d6 to your computer and use it in GitHub Desktop.
<?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