0

I would like to run part of php code asynchronously. I want to run the insertnumber() function after 60seconds but without delaying the whole code.

 echo json_encode($returnArray);
 if ($timeout=="1")
{
  sleep(60);
  $connection->insertnumber($finalnumber,"Loser");
} 

This method delay the whole code by 60 secs. I want that part of the code to run in the background without affecting the original code and then executing the insernumber() function after 60 secs.

1

1 Answer 1

0

PHP by default runs synchronously. Have a look at the following question which has a few different methods on how to run PHP asynchronously, using either PHP OOP Threads or some built it PHP Process methods:

How can one use multi threading in PHP applications

Additionally, if you are building something that will be running in the browser, have a look at using Javascript asynchronous functions to achieve what you desire:

What is a simple example of an asynchronous javascript function?

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.