symfony / panther

A browser testing and web crawling library for PHP and Symfony
MIT License
2.91k stars 213 forks source link

Chrome client crontab #622

Open XhonorSkillline opened 5 months ago

XhonorSkillline commented 5 months ago

When using the functionality via cron, the file completes its work before receiving the result from ChromeClient (even with the wait functionality). What to do in this case? How can I make cron wait for the results from the browser to complete?

function example($url) {
        $client = Client::createChromeClient(null, null, [
            'port' => $availablePort,
        ]);

        $client->request('GET', $url);
        $client->waitForElementToContain('body', '{"status":"success"', 10);
        $data = $client->getCrawler()->filter('body')->text();

        $client->quit();

        return $data;
}

Cron function:

foreach($lala as $url) {
        $data[] = example($url);
}

print_r($data); // empty result instantly without waiting