Hướng dẫn sleep milliseconds in php

Does PHP provide a function to sleep in milliseconds?
Right now, I'm doing something similar to this, as a workaround.

$ms = 10000;
$seconds = round[$ms / 1000, 2];
sleep[$seconds];

I'd like to know whether there is a more generic function that is available in PHP to do this, or a better way of handling this.

asked Nov 2, 2017 at 3:29

Navaneeth MohanNavaneeth Mohan

5171 gold badge5 silver badges9 bronze badges

3

This is your only pratical alternative: usleep - Delay execution in microseconds

So to sleep for two miliseconds:

usleep[ 2 * 1000 ];

To sleep for a quater of a second:

usleep[ 250000 ];

Note that sleep[] works with integers, sleep[0.25] would execute as sleep[0] Meaning this function would finish immediatly.

$i = 0;
while[ $i < 5000 ]
{
  sleep[0.25];
  echo '.';
  $i++;
}
echo 'done';

answered Nov 2, 2017 at 3:31

2

Not the answer you're looking for? Browse other questions tagged php synchronization sleep or ask your own question.

Hướng dẫn strtolower php

Tác dụng của hàm strtolower[]The strtolower[] function converts a string to lowercase.The following table summarizes the technical details of this function. Return Value:Returns the modified ...

Hướng dẫn dùng echo b trong PHP

Hàm echo[] trong PHP được dùng để hiển thị dữ liệu ra màn hình.Cú phápecho strings;

Chủ Đề