简体   繁体   中英

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));

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM