title: How to limit FTP connection time
body: <p>I have FTP server with IP public, let say: 192.0.0.12. But in some area with different  network, connection to this IP is not applicable. In this case, we can connect to the FTP through another IP, let say: 171.0.0.13. </p>
  
  <p>So I have write script in PHP to connect to the FTP server and download the files by using <code>ftp_connect()</code>. To avoid the long respond, I set the time limit to 5 seconds using <code>set_time_limit()</code>. This is the script:</p>
  
  <pre><code>&lt;?php
  include "config.php";
  function ftp_konek($ftp_server){
      set_time_limit(5);
      $conn_id = ftp_connect($ftp_server);
      return $conn_id;
  }
  if(ftp_konek($ftp_server)){
      /*download the file*/
  }else{
      $ftp_server = "171.0.0.13";
      $change_ip = ftp_konek($ftp_server);
      if($change_ip){
         /*download the file*/
      }else{
         echo "Failed!";
      }
  }
  ?&gt;
  </code></pre>
  
  <p>The public IP and username+password are stored in the <code>config.php</code>. The idea is:</p>
  
  <ol>
  <li>Connect to FTP server using the first IP.</li>
  <li>If succeed in 5 seconds, download the file.</li>
  <li>Else if not succeed, change the FTP server IP and connect.</li>
  <li>If connection succeed, download the file</li>
  </ol>
  
  <p>The problem is, I got warning: </p>
  
  <blockquote>
    <p>Fatal error: Maximum execution time of 5 seconds exceeded</p>
  </blockquote>
  
  <p>And the operation stopped. </p>
  
  <p>Any ideas?</p>