title: Solve idle-timeout between apache and php-fpm using FastCgiExternalServer
body: <p>I'm using apache version 2.2.15 and php-fpm with php 7.1.12 and I have them communicating via a unix socket, </p>
  
  <p>in my apache configuration I have this setup with FastCgiExternalServer as follows</p>
  
  <pre><code>FastCgiExternalServer /var/www/cgi-bin/php-fastcgi -idle-timeout 30 -socket /var/run/php-fpm/www.sock -pass-header Authorization
  </code></pre>
  
  <p>The issue that I have is that with scripts that take a long time to execute, apache dies out with a 500 error once the idle-timeout of 30 seconds is reached. And my problem is that I cannot change the idle-timeout set in the FastCgiExternalServer line above.</p>
  
  <p>Now if my script returns texts regularly (and execute a flush()) this ilde-timeout is never reached, the script keeps running and apache returns the result once it is done. 
  Unfortunately the script I need to run cannot echo random text during it's execution, but if I could return a "keepalive" message on the socket level that would probably prevent apache form reaching that idle-timeout.</p>
  
  <p>I am surprised that I haven't yet found a setting in php-fpm that makes it send a keepalive signal back to apache while it is running the script. Maybe there is such a setting, if so I'd love to know about it.</p>
  
  <p>Now, it this cannot be set on within the settings of php-fpm that maybe could be done on within the php code, perhaps using the socket_set_option() function or socket_sendmsg() or something similar</p>
  
  <pre><code>socket_set_option($sock, SOL_SOCKET, SO_KEEPALIVE, 1)
  </code></pre>
  
  <p>yet I haven't found how to get this to work. I tried to use php://output in various way but haven't got it to work.</p>
  
  <p>So my question is do you know of any way to have php-fpm or a php-script to send back to apache some sort of signal that would prevent the idle-timeout to be reached and wouldn't pollute the final output with unwanted characters. </p>
  
  <p>thanks</p>