You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
1.4 KiB

  1. <h1>PHP</h1>
  2. <p>Below is an example of making a HTTP request to SITE_NAME from PHP.</p>
  3. <div class="php highlight"><pre><span></span><code><span class="nb">file_get_contents</span><span class="p">(</span><span class="s1">&#39;PING_URL&#39;</span><span class="p">);</span>
  4. </code></pre></div>
  5. <p>If you would like to setup timeout and retry options, as discussed in the
  6. <a href="../reliability_tips/">reliability tips section</a>, there is a
  7. <a href="https://www.phpcurlclass.com/">curl package</a> available that lets you do that easily:</p>
  8. <div class="php highlight"><pre><span></span><code><span class="k">use</span> <span class="nx">Curl\Curl</span><span class="p">;</span>
  9. <span class="nv">$curl</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">Curl</span><span class="p">();</span>
  10. <span class="nv">$curl</span><span class="o">-&gt;</span><span class="na">setRetry</span><span class="p">(</span><span class="mi">20</span><span class="p">);</span>
  11. <span class="nv">$curl</span><span class="o">-&gt;</span><span class="na">setTimeout</span><span class="p">(</span><span class="mi">5</span><span class="p">);</span>
  12. <span class="nv">$curl</span><span class="o">-&gt;</span><span class="na">get</span><span class="p">(</span><span class="s1">&#39;PING_URL&#39;</span><span class="p">);</span>
  13. </code></pre></div>
  14. <p>Note: this code does not throw any exceptions.</p>