When I run PHP Code sniffer on my code, I see the below warning.

WARNING | The use of function sleep() is discouraged (Magento2.Functions.DiscouragedFunction.Discouraged)

Which class method provides an alternative for the sleep() method in Magento 2 framework that fixes the above warning and follows the magento best practice.

  • Have you found solution? I'm facing same issue. Thanks.
    – Raj
    May 14, 2020 at 6:34
  • I found a temporary solution. I answered it here. Please check.
    – nikin
    May 14, 2020 at 6:52

2 Answers 2


Modify the code from



// phpcs:ignore Magento2.Functions.DiscouragedFunction

This is just a temporary solution where in the codesniffer ignores the evaluation of the discouraged function when prepended with the comment phpcs:ignore Magento2.Functions.DiscouragedFunction

  • It is just ignore the code during codesniffer. Try solution given by me. Hope it works for you. Thanks.
    – Raj
    May 14, 2020 at 6:53
  • Hi Nitkin, I have used // phpcs:ignore Magento2.Functions.DiscouragedFunction which you have recommended for html_entity_decode() method but when I am generating report still the same warning is appearing. can you pls advise Oct 28, 2022 at 8:24

I have found solution. We have to use usleep function which is working same like sleep function.

Only difference is that usleep function works in microseconds so you have to covert second into microsecond and it's work like a charm.

For example:-

sleep(2); //2 seconds delay here
usleep(2000000);  //2000000 microseconds = 2 seconds
  • Hahahah this is Magento !!! In a couple of days they'll add usleep as well hahaha May 27, 2021 at 1:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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