问题
I'm using Selenium stanalone + Chrome headless + PHP + UwAmp server on my computer to parse some data (system: WIN7_32bit, 4GB RAM).
I need to start 22 Chrome sessions at the same time so I'm using selenium grid with this settings:
java -jar selenium-server-standalone-2.53.1.jar -role hub
java -jar selenium-server-standalone-2.53.1.jar -role node -hub http://localhost:4444/grid/register -browser "browserName=chrome,maxInstances=22,seleniumProtocol=WebDriver" -maxSession 22
My problem is that mainly 6 session are started (example on pictures)... Sometimes there are 2 or 4 active sessions. What am I doing wrong? I tried to make changes in php.ini but withouth success. These are the settings:
EDIT: my php.ini file
EDIT2: since same thing happens on other workstation (WIN10_64bit, Intel i7, 16GB RAM), I think that this problem has something to do with UwAmp server settings, or selenium-server-standalone-2.53.1.jar, or Google Chrome.
回答1:
Browser connection limitations - exactly that is the problem.
I'm working with PHP (server side language) and I need to execute my PHP scripts somehow. The solution is some local server (like uWamp) and some web browser that opens the script on that server. Since I need to start 22 scripts, at the same time i open 22 browser tabs with this addresses:
http://localhost/selenium/PHPWebDriver/1.php
http://localhost/selenium/PHPWebDriver/2.php
....
http://localhost/selenium/PHPWebDriver/22.php
Now, Chrome limit the number of HTTP connections with the same domain name. This restriction is defined in the HTTP specification (RFC2616) and most modern browsers allow only six connections per domain (Opera, Safari, Chrome, Firefox...)!
So, way to get around browser limits is to:
- change the browser limit if plaussible (Firefox), not for Chrome
- download browser sources and rebuild them (like Chromium),
- providing multiple subdomains,
- make user profile for each script (argument for Chrome: '--user-data-dir=').
Maybe there are some other solutions, I don't know...
I decided to go on option 3 since I can't change limits in Chrome.
SOLUTION:
1) Open C:\Windows\System32\drivers\etc\hosts using Notepad
2) Add the following line to the bottom of your hosts file for every subdomain:
127.0.0.1 localhost
127.0.0.1 localhost2
127.0.0.1 localhost3
127.0.0.1 localhost4
(I had to add 4 subdomains because on each subdomain I can execute only 6 scripts)
Now you can start:
http://localhost/selenium/PHPWebDriver/1.php
...
http://localhost/selenium/PHPWebDriver/6.php
http://localhost2/selenium/PHPWebDriver/7.php
...
http://localhost2/selenium/PHPWebDriver/13.php
http://localhost3/selenium/PHPWebDriver/14.php
...etc...
And that's it. Notice that on some servers you might need to make some changes in Apache httpd-vhosts.conf for this to work.
来源:https://stackoverflow.com/questions/48357644/selenium-grid-sessions-not-applied