views:

20

answers:

0

I have a PHP script that connects to remote servers and downloads specific files. However, I am running into issues where the script is just stopping. I am using a context to try to get diagnostic output, but the script just stops after outputting "Connecting...". Is there a way that I can get additional output?

This is the call to the stream opener I am using:

$ctx = stream_context_create();
stream_context_set_params($ctx, array("notification" => "stream_notification_callback"));
$handle = @fopen("https://" . $server . "/" . $path, "r", FALSE, $ctx);

In the callback function, I am displaying all of the output except STREAM_NOTIFY_PROGRESS.

This is all of the output I get:

Connecting...

I think there should be more output. I have even noticed that I don't get notified when the socket completes or the connection is closed. This is especially worrisome because I have a line that outputs "Download Complete" once the file has been read, and sometimes execution stops before that line. I am sure the script is not timing out.

Edit As requested, here is the code for the callback function:

function stream_notification_callback($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max) {

  switch($notification_code) {
    case STREAM_NOTIFY_RESOLVE:
    case STREAM_NOTIFY_AUTH_REQUIRED:
    case STREAM_NOTIFY_COMPLETED:
    case STREAM_NOTIFY_FAILURE:
    case STREAM_NOTIFY_AUTH_RESULT:
      var_dump($notification_code, $severity, $message, $message_code, $bytes_transferred, $bytes_max);
      break;
    case STREAM_NOTIFY_REDIRECTED:
      echo "Being redirected to: ", $message;
      break;
    case STREAM_NOTIFY_CONNECT:
      echo "Connected...";
      break;
    case STREAM_NOTIFY_FILE_SIZE_IS:
      echo "Got the filesize: ", $bytes_max;
      break;
    case STREAM_NOTIFY_MIME_TYPE_IS:
      echo "Found the mime-type: ", $message;
      break;
    case STREAM_NOTIFY_PROGRESS:
      //echo "Made some progress, downloaded ", $bytes_transferred, " so far";
      break;
  }
  echo "\n";
}