gustavo martins
gustavo martins

Reputation: 83

How can I delay the execution time of a php script, so the python script can finish

I have a script in php that is calling a python one, which is a neural network being trained and it takes about 80 seconds to finish, but my php script finishes fast.

I tried just creating a csv file in python which is a quick process, and it worked, so its really a question of time.

I've already tried using the following code, and it didn't worked.

var_dump(time_sleep_until(microtime(true)+100));

Upvotes: 0

Views: 265

Answers (3)

Patrick Fay
Patrick Fay

Reputation: 560

usleep(100); is more intuitive for what you are trying to do than using time_sleep_until, although I believe your time_sleep_until should work pretty similarly. However, the manual for time_sleep_until() seems to suggest that it may not work consistently for short times (such as .2 seconds). I would try usleep instead.

Upvotes: 0

Damian Dziaduch
Damian Dziaduch

Reputation: 2127

Just use the Symphony Process component -> https://symfony.com/doc/current/components/process.html

It allows you to run processes asynchronously and check whether they are still running: https://symfony.com/doc/current/components/process.html#running-processes-asynchronously

Cheers.

Upvotes: 1

Will
Will

Reputation: 389

Straight from the manual

https://www.php.net/manual/en/function.sleep.php

sleep ( int $seconds ) : int

Delays the program execution for the given number of seconds.

Parameters ¶

seconds Halt time in seconds.

Return Values ¶

Returns zero on success, or FALSE on error.

If the call was interrupted by a signal, sleep() returns a non-zero value. On Windows, this value will always be 192 (the value of the WAIT_IO_COMPLETION constant within the Windows API). On other platforms, the return value will be the number of seconds left to sleep.

Errors/Exceptions ¶

If the specified number of seconds is negative, this function will generate a E_WARNING.

Upvotes: 0

Related Questions