0

I'm working on a script that a server posts to us and we post to a server and theoretically is supposed to receive a response from the server and reply back to the server that posted to us. However sometimes the server I'm posting to doesn't respond. The big problem is the server that posted to us will assume the transaction went through successfully unless it hears otherwise. So essentially I need a way to send a response back to the first server if I never hear back from the server I'm posting to. I think register_shutdown_function could work for me but I don't know how to set that up so it only runs on error or whatever.

Thanks in advance

4

1 に答える 1

1

register_shutdown_function()あなたのために働くはずです。グローバル変数を使用して、リモートサーバーが応答したかどうかを判断するだけです。

<?php

  function on_shutdown () {
    if (!$GLOBALS['complete']) {
      // Handle server not responding here
    }
  }

  // Suppress "FATAL ERROR" message when time limit reached
  error_reporting(0);

  $complete = FALSE;

  register_shutdown_function('on_shutdown');

  // Code which posts to remote server here

  $complete = TRUE;

これは$complete、リモートサーバーに投稿するコードが完了しない場合でもfalseになることを意味するため$complete、シャットダウン時に起動する関数の真実性を確認できます。

于 2012-04-20T16:12:06.633 に答える