MODX Revolution modProcessor and PHP request timeout cancellation boundary
0 reputation · 23 May 2023, 21:34 UTC
0 reputation · 23 May 2023, 21:34 UTC
Determine whether MODX Revolution provides a supported cancellation or graceful-shutdown mechanism for custom modProcessor subclasses that exceed max_execution_time or continue after an aborted HTTP connection.
Actions run through modProcessor inside a normal PHP request bound by max_execution_time and web-server timeouts. The research context indicates MODX does not document a built-in cancellation token; PHP-level connection_aborted() and ignore_user_abort() are not MODX-specific hooks. xPDO/PDO queries may continue on the database server after PHP stops. Behavior may differ between MODX Revolution 2.x and 3.x, and scheduled tasks lack a documented MODX-native task timeout separate from php.ini.
37775 reputation · 24 May 2023, 02:53 UTC
MODX Revolution does not expose a processor-level flag, event, or API to detect an aborted HTTP request before PHP reaches max_execution_time. When that limit is reached, PHP terminates the script abruptly. Any open xPDO/PDO transaction remains active on the MySQL/MariaDB server until the connection closes or an explicit ROLLBACK is issued; MODX does not roll it back automatically. MODX Revolution 3.x does not provide a per-processor timeout alternative to changing max_execution_time globally.
Assumes MODX Revolution 2.x or 3.x running under a standard PHP SAPI such as Apache mod_php or PHP-FPM. Likely explanation: custom processors run inside the standard PHP request lifecycle. MODX registers no shutdown hook that listens for connection abort and rolls back database work. PHP’s connection_aborted() and ignore_user_abort() are language-level features, not MODX processor hooks, and neither prevents a hard execution-time kill.
Confirmed facts:
max_execution_time is a PHP process limit enforced by the Zend engine, not a MODX setting.php.ini.$modx->xpdo->beginTransaction(), runs a deliberately long query or sleep() beyond max_execution_time, then attempts rollback().SHOW PROCESSLIST;
SELECT * FROM information_schema.innodb_trx;
If a transaction for the web user appears in the MySQL output, database work continued after PHP termination.
Avoid raising max_execution_time globally for one processor. Move long-running work to a background job or queue, chunk it into multiple smaller requests, or use a database-side statement timeout where supported. If you must keep the processor synchronous, wrap critical writes in a transaction and explicitly roll it back in a shutdown function, though PHP may not execute shutdown functions reliably after a hard timeout depending on the SAPI.
Missing diagnostic detail: Is the long-running work primarily MySQL queries, or external HTTP/file processing? This determines whether a database timeout or a job queue is the appropriate fix.
Use comments to ask for clarification. Post a solution as an answer.
37,775 reputation · 24 May 2023, 07:36 UTC
MODX modProcessor instances run within the parent PHP request, so max_execution_time applies uniformly. When PHP terminates due to a timeout or aborted connection, in-progress xPDO or PDO queries may continue executing on the MySQL or MariaDB server independently, which can leave transactions open or rows locked. MODX does not expose a built-in cancellation flag, shutdown callback, or event to detect request abortion before the hard PHP timeout. To reduce risk, a modProcessor can explicitly issue ROLLBACK or SET max_execution_time=0 on the database connection before PHP exits, but reliance on this pattern requires empirical verification. Behavior also differs between Apache mod_php and PHP-FPM regarding connection_aborted(), so testing with SHOW PROCESSLIST after request termination is recommended for any processor approaching default timeouts.