title: fopen() failed to open stream: HTTP request failed - Zabbix API
body: <p>I have 2 servers: 1 LAMP web server where I have my webpages, and another server with Zabbix installed for monitoring things. My web server connects to the Zabbix server with a PHP script and uses the Zabbix API to read data and render graphs with Google Charts. I'm using this script to be exact: <a href="http://zabbixapi.confirm.ch/" rel="nofollow">http://zabbixapi.confirm.ch/</a></p>
  
  <p>The script was working great for a few months, and all of a sudden last week it became strange and started saying <code>failed to open stream: HTTP request failed</code>. The PHP Zabbix API script uses <code>fopen</code>, so I tried changing it to curl, but it still acted exactly the same. I noticed that the script can call the Zabbix API once to log in and get the authentication code, but then when it tries to make the 2nd API call to read the data, that's where it is hanging and gives me the error. If I add a <code>sleep(30)</code> in between the API calls, it works!</p>
  
  <p>I installed a LAMP server on my local machine to test out the same script, and it works fast with no errors, and no sleep() line.</p>
  
  <p>So I think something is limiting the rate that I can make the API calls (from the web server to the Zabbix server) and I cannot figure out what it is. Anybody have any ideas?</p>
  
  <p>Btw, the PhpZabbixAPI library doesn't have an <code>fclose()</code> line. Will that affect anything?</p>
  
  <p>Here's some sample outputs:</p>
  
  <pre><code>1st API request: {"jsonrpc":"2.0","method":"user.login","params":{"user":"username","password":"password"},"auth":"","id":"13969720350853"}
  
  Response: {"jsonrpc":"2.0","result":"cec4e961ddb7d193250d089f70d81e2e","id":"13969720350853"}
  
  2nd API request: {"jsonrpc":"2.0","method":"history.get","params":{"output":"extend","itemids":["23713","23689","23707","23695"],"limit":96,"sortfield":"clock","sortorder":"DESC","history":0},"auth":"cec4e961ddb7d193250d089f70d81e2e","id":"13969720358004"}
  
  Response: Could not connect to "http://&lt;zabbixserver&gt;/zabbix/api_jsonrpc.php"
  </code></pre>
  
  <p>Also happens if I use file_get_contents too quickly in the CLI from the web server:</p>
  
  <pre><code>~# php -r "echo file_get_contents('http://&lt;zabbix&gt;/zabbix/index.php') or die(print_r(error_get_last(),true));"
  1
  ~# php -r "echo file_get_contents('http://&lt;zabbix&gt;/zabbix/index.php') or die(print_r(error_get_last(),true));"
  Array
  (
      [type] =&gt; 2
      [message] =&gt; file_get_contents(http://&lt;zabbix&gt;/zabbix/index.php): failed to open stream: HTTP request failed! 
      [file] =&gt; Command line code
      [line] =&gt; 1
  )
  </code></pre>