Trongate MX Docs
Introduction
Core HTTP Operations
Swapping Content
Events & Responses
Dynamic Form Handing
UI Enhancements
Data Management
Form Handling
Advanced Features
Trongate MX Security
Reference

Handling Request Timeouts

The mx-timeout and mx-on-timeout attributes control how long requests wait for a response and what happens when they take too long. These are essential for long-running operations like AI analysis, file uploads, or complex processing.

By default, Trongate MX waits 60 seconds before timing out a request.

The mx-timeout Attribute

Specify how long (in milliseconds) to wait for a server response:

Pure HTML syntax:

Disabling Timeouts

Set to "none" or "0" to disable (use sparingly):

Disabling timeouts means requests could wait indefinitely if there's a problem. Only use this when absolutely necessary.

The mx-on-timeout Attribute

Execute custom JavaScript when a timeout occurs:

Pure HTML syntax:

Receiving Event Information

Your timeout function receives an event object with details:

Practical Examples

1. User-Friendly Timeout Message


2. Retry Logic with Redirect

Best Practices:

  • Set realistic timeouts based on expected operation duration
  • Always provide user feedback when timeouts occur
  • Consider retry logic for operations that might succeed on second attempt
  • Test timeout handling with various network conditions

⚠️ Critical: PHP Session Locking

If your timeout handler redirects to another page and the browser appears to "hang," this is caused by PHP session locking.

The Problem: PHP locks the session file during script execution. If your script is processing a long task, the session remains locked. When the timeout redirect tries to load a new page that needs the session, that page hangs waiting for the lock.

The Solution: Call session_write_close(); after authentication, before long operations:

This allows users to navigate elsewhere while your script continues processing.

Combining Timeout Attributes

Use both attributes together for complete control:

You can use mx-on-timeout alongside mx-on-success and mx-on-error for comprehensive request handling.

Learn more: Handling Successful Requests | Handling Request Errors

Things to Keep in Mind

  • Timeout values are in milliseconds (30000 = 30 seconds)
  • Default timeout is 60 seconds when not specified
  • Timeouts differ from errors - timeouts occur when no response is received
  • Works with all HTTP methods (mx-get, mx-post, mx-put, mx-delete, mx-patch)
  • For long operations with redirects: always call session_write_close() server-side

We're continually improving the Trongate documentation. If anything is incorrect, unclear, incomplete, or could be better, we'd genuinely appreciate your input.

Share your thoughts in the Documentation Feedback.

Leave Feedback About This Page