Running tabs concurrently chrome-php

112 Views Asked by At

I'm trying to open 20 concurrent tabs in chrome browser using php and chrome-php library.
Each tab navigates to the URL, evaluates some js code, and gets the data from the page.

foreach ($urls as $url) {
    $page = $this->browser->createPage();

    $page->navigate($url)->waitForNavigation();
    $page->close();
}

If I'm trying to use Spatie\Async\Pool

$pool = Pool::create();

foreach ($urls as $url) {
    $pool[] = async(function () use ($url) {
      $page = $this->browser->createPage();

      $page->navigate($url)->waitForNavigation();
      // evaluate js code
      $page->close();
    });
}

await($pool);

I get this error:
Cannot assign Laravel\SerializableClosure\Serializers\Native to property Symfony\Component\Console\Input\InputArgument::$suggestedValues of type Closure|array

Running sequentially will take a lot of time, is that possible to achieve concurrency?

0

There are 0 best solutions below