If no activity on my site for ≈30 minutes, PHP fsockopen page times out with blank page no error messages...tried all the error reporting settings

StackOverflow https://stackoverflow.com/questions/20939497

  •  24-09-2022
  •  | 
  •  

Question

I have a Web application/site that is hosted on IIS 8.0. The site is written using PHP 5.3, and gets its data from a connection to a database using PHP's odbc_connect() function.

On two of the pages on my site, an E-mail must be sent to the user for him or her to activate a forum post. I am currently using a home-brewed SMTP method that utilizes fsockopen() for sending the E-mails.

The problem is as follows:

If ≈30 minutes goes by during which the site is not visited by the user, and they visit the page that sends the E-mail, the page will completely time out according to PHP's max_execution_time value, with no data being sent to the user's browser (the user sees a blank page).

HOWEVER, the E-mail is still sent, and every bit of code on that page is executed! How do I know? I created a log file that gets written to at the very end of the suspect page, and it always gets written to, even though the page times out. If the user backs out of the blank page, and submits the E-mail again, it magically works!

Things I have tried, that did not change a thing:

  1. Tried using PHP PEAR mail
  2. Tried using PHPMailer
  3. Tried using PHP Swift Mailer
  4. Tried using flush()
  5. Tried using ob_flush()
  6. Tried increasing PHP's max_execution_time (this just make the timeout longer)
  7. Tried using non-blocking mode on fsockopen with stream_set_blocking();
  8. Tried using PHP 5.4 / 5.3 / 5.2
  9. Tried setting error_reporting(E_ALL);
  10. Tried setting ini_set("display_errors", 1);
  11. Tried setting ini_set("display_startup_errors", 1);

All I get is a blank screen after 30 minutes of idle time, with no error messages.

Does anyone have any ideas? Remember, all the code on the page gets executed, but it seemingly never stops "processing" until it times out.

example code:

<?php
include("functions.php"); //contains "smtp_mail" and "logwrite" functions

odbc_connect($connectionstring,$username,$password);

$mail = smtp_mail($recipient, $subject, $message);

echo "made it here"; //this never makes it to the user's browser!

logwrite("made it here"); //this is always executed, but still times out!
?>
Was it helpful?

Solution

It turns out the issue resided on my host's end. I changed hosts and the code posted above works fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top