This example illustrates Connection Manager's built-in transaction timeout functionality.
Click the "Create Two Transactions" button below. Two requests will be made to a PHP script that is designed to respond slowly, waiting between 0 and 10 seconds to respond. If the response takes longer than 1.5 seconds, the request will automatically abort (resulting in a "transaction aborted" message).
The following code example provides a step-by-step approach to presetting a transaction timeout.
The callback object includes a
timeout property that allows you to specify the amount of time you're willing to wait for a transaction to complete before aborting. To cause a transaction to automatically timeout, the
timeout property must be defined wih a value in millseconds. This example defines timeout with a value of 5000(milliseconds). If the transaction is not complete within 5000ms, it will be aborted.
YAHOO.util.Connect.asyncRequest to send the request to
sync.php. The PHP script will return a string message after a random delay of 0 to 10 seconds if the transaction was not aborted. If the transaction was successfully aborted, the response object's status property will report
-1 and the
statusText property will report "transaction aborted".
Note: Logging and debugging is currently turned off for this example.
All YUI 2.x users should review the YUI 2.8.2 security bulletin, which discusses a vulnerability present in YUI 2.4.0-2.8.1.