title: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY" with Selenium and PHPUnit
body: <p>I am doing running all tests using PHPUnit. Created a wrapper that launches an instance of Apache, then starts the Selenium standalone server, then creates the Chrome Remote Webdriver instance at <a href="http://localhost:4444/wd/hub" rel="nofollow noreferrer">http://localhost:4444/wd/hub</a>. This process works 100% of the time on our dev machines, and 90% of the time on the test server, but from time to time, the tests fail as such:</p>
  
  <pre><code> [exec] 1) Intranet\Pages\FinancialReportsSeleniumTest::test_changeMonthYear
   [exec] Facebook\WebDriver\Exception\WebDriverCurlException: Curl error thrown for http POST to /session with params: {"desiredCapabilities":{"browserName":"chrome","platform":"ANY","chromeOptions":{"binary":"","args":["--window-size=1400,900","--no-sandbox","--headless"]},"goog:chromeOptions":{"args":["--window-size=1400,900","--no-sandbox","--headless"]}}}
   [exec] 
   [exec] Failed to connect to localhost port 4444: Connection refused
   [exec] 
   [exec] C:\Jenkins\jobs\Intranet-Master\workspace\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php:292
   [exec] C:\Jenkins\jobs\Intranet-Master\workspace\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:126
   [exec] C:\Jenkins\jobs\Intranet-Master\workspace\phpunit\library\Intranet\Selenium.php:364
   [exec] C:\Jenkins\jobs\Intranet-Master\workspace\phpunit\library\Intranet\Selenium.php:51
   [exec] C:\Jenkins\jobs\Intranet-Master\workspace\phpunit\library\Intranet\SeleniumTestCase.php:9
  </code></pre>
  
  <p>If we re-run the tests, works fine the next time.</p>
  
  <p>Dev Machines:</p>
  
  <ul>
  <li>Windows 10 Pro (1809) (64 bit)</li>
  <li>Apache 2.4.38 (32 bit)</li>
  <li>PHP 7.2.15 (32 bit)</li>
  <li>Java 1.8.0_192 (64 bit)</li>
  <li>Selenium 3.141.59</li>
  <li>Selenium Chrome Driver 73.0.3683.20</li>
  </ul>
  
  <p>Test Machine</p>
  
  <ul>
  <li>Windows Server 2008 R2 x64 (64 bit)</li>
  <li>Apache 2.4.38 (32 bit)</li>
  <li>PHP 7.2.15 (32 bit)</li>
  <li>Jenkins 2.1.64</li>
  <li>Java 1.8.0_192 (64 bit)</li>
  <li>Selenium 3.141.59</li>
  <li>Selenium Chrome Driver 73.0.3683.20</li>
  </ul>
  
  <p>Log file shows that the server is up:</p>
  
  <pre><code>10:41:27.392 INFO [GridLauncherV3.launch] - Selenium build info: version: '3.14.0', revision: 'aacccce0'
  10:41:27.392 INFO [GridLauncherV3$1.launch] - Launching a standalone Selenium Server on port 4444
  10:41:28.562 INFO [SeleniumServer.boot] - Selenium Server is up and running on port 4444
  </code></pre>
  
  <p>UPDATE #1: We now start the Selenium standalone server as a Service, still fails about the same frequency (once every 5-10 test runs).</p>
  
  <p>UPDATE #2: We now start the Apache instance and the remote web driver at as part of our PHPUnit bootstrap file, before any tests are run. We also now test that the web driver is running (first, before attempting to start it), using fsockopen(). The failure rate has dropped to less than 5%, but it still happens from time to time. Strange thing is, the improvement actually seemed to occur after we add the fsockopen() call - maybe there is timing issue of some kind?</p>