PHP file fatal error

Some time ago, I wrote Perl scripts import the output from a PHP file using LWP. However, recently I am getting tons of errors on the log, resulting in PHP file fatal error. Code is below.

AH01220: Timeout waiting for output from CGI script /home/example/public_html/cgi-bin/script.cgi, referer

Script timed out before returning headers: script.cgi, referer

How can I get this fixed?