Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a set time out equivalent in php?

Tags:

javascript

php

Is there a PHP equivalent to setting timeouts in JavaScript?

In JavaScript you can execute code after certain time has elapsed using the set time out function.

Would it be possible to do this in PHP?

like image 547
kamikaze_pilot Avatar asked Jun 26 '11 19:06

kamikaze_pilot


People also ask

What is alternative to setTimeout?

The setInterval method has the same syntax as setTimeout : let timerId = setInterval(func|code, [delay], [arg1], [arg2], ...) All arguments have the same meaning. But unlike setTimeout it runs the function not only once, but regularly after the given interval of time.

What is set time out method?

The setTimeout() method executes a block of code after the specified time. The method executes the code only once. The commonly used syntax of JavaScript setTimeout is: setTimeout(function, milliseconds);

How do I pass parameters to setTimeout?

You can pass the parameter to the setTimeout callback function as: setTimeout(function, milliseconds, param1, param2, ...) eg. Yeah!

How many arguments will setTimeout take?

Bookmark this question. Show activity on this post. This SO answer makes a call to setTimeout with four arguments.


1 Answers

PHP is single-threaded, and in general PHP is focused on the HTTP request cycle, so this would be tricky to allow a timeout to run code, potentially after the request is done.

I can suggest you look into Gearman as a solution to delegate work to other PHP processes.

like image 176
Bill Karwin Avatar answered Oct 06 '22 14:10

Bill Karwin