panther
panther copied to clipboard
Get error RuntimeException: The port 9515 is already in use
This is my code: `require "vendor/autoload.php"; use Symfony\Component\Panther\Client;
$client = Client::createChromeClient(); $crawler = $client->request('GET', 'https://www.marathonbet.ru/su/popular/Football'); `
And full error text:
[Fri Nov 01 17:29:08.794482 2019] [php7:error] [pid 6766] [client ::1:40280] PHP Fatal error: Uncaught RuntimeException: The port 9515 is already in use. in /var/www/html/vendor/symfony/panther/src/ProcessManager/WebServerReadinessProbeTrait.php:36\nStack trace:\n#0 /var/www/html/vendor/symfony/panther/src/ProcessManager/ChromeManager.php(47): Symfony\\Component\\Panther\\ProcessManager\\ChromeManager->checkPortAvailable('127.0.0.1', 9515)\n#1 /var/www/html/vendor/symfony/panther/src/Client.php(87): Symfony\\Component\\Panther\\ProcessManager\\ChromeManager->start()\n#2 /var/www/html/vendor/symfony/panther/src/Client.php(295): Symfony\\Component\\Panther\\Client->start()\n#3 /var/www/html/vendor/symfony/panther/src/Client.php(197): Symfony\\Component\\Panther\\Client->get('https://www.mar...')\n#4 /var/www/html/index.php(7): Symfony\\Component\\Panther\\Client->request('GET', 'https://www.mar...')\n#5 {main}\n thrown in /var/www/html/vendor/symfony/panther/src/ProcessManager/WebServerReadinessProbeTrait.php on line 36
Same here.
In the meantime, i am killing each time the chrome instance with the following command
kill $(lsof -i:9515)
but it's a pain.
Is there a method to shut down the instance after usage?
Thank you
There is a close()
method in the Client
to close the window. Are you using it?
Thank you for the tip! It put me on the right track
Looking at comments in the Webdriver class used in the background of the Symfony\Component\Panther\Client
class, I found that quit
is a better method to use than close
for closing the window AND the session
/**
* Close the current window.
*
* @return WebDriver The current instance.
*/
public function close();
/**
* Quits this driver, closing every associated window.
*/
public function quit();
And then we can use try/catch/finally to make sure that the quit function is used as following:
$client = \Symfony\Component\Panther\Client::createChromeClient();
try {
//code here
//$crawler = $client->request('GET', 'https://www.example.com');
//$client->clickLink('Log in');
} catch (Exception $e) {
echo $e->getMessage();
} finally {
$client->quit();
}
Teardown => quit() ?
I already used the quit
method after every request but sometimes it suddenly gets errors and cannot quit.
I was able to solve my problem with this idea: https://jelledev.com/how-to-run-multiple-symfony-panther-clients-in-parallel/