PHP's set_time_limit in TypeScript

How to use

Install via yarn add locutus and import: import { set_time_limit } from 'locutus/php/info/set_time_limit'.

Or with CommonJS: const { set_time_limit } = require('locutus/php/info/set_time_limit')

Use a bundler that supports tree-shaking so you only ship the functions you actually use. Vite, webpack, Rollup, and Parcel all handle this. For server-side use this is less of a concern.

Examples

These examples are extracted from test cases that automatically verify our functions against their native counterparts.

#codeexpected result
1set_time_limit(4)undefined

Dependencies

This function uses the following Locutus functions:

Here's what our current TypeScript equivalent to PHP's set_time_limit looks like.

import { getPhpRuntimeBoolean, setPhpRuntimeEntry } from '../_helpers/_phpRuntimeState.ts'

export function set_time_limit(seconds: number): void {
// discuss at: https://locutus.io/php/set_time_limit/
// original by: Brett Zamir (https://brett-zamir.me)
// test: skip-all
// example 1: set_time_limit(4)
// returns 1: undefined

setTimeout(function () {
if (!getPhpRuntimeBoolean('timeoutStatus', false)) {
setPhpRuntimeEntry('timeoutStatus', true)
}
throw new Error('Maximum execution time exceeded')
}, seconds * 1000)
}

Improve this function

Locutus is a community effort following The McDonald's Theory: we ship first iterations, hoping others will improve them. If you see something that could be better, we'd love your contribution.

View on GitHub · Edit on GitHub · View Raw


« More PHP info functions


Star