php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66769 sleep function wrong definition
Submitted: 2014-02-25 14:58 UTC Modified: 2014-02-26 09:35 UTC
From: aryans dot vinay at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: Irrelevant OS: any
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: aryans dot vinay at gmail dot com
New email:
PHP Version: OS:

 

 [2014-02-25 14:58 UTC] aryans dot vinay at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.sleep
---

This document describe sleep() as follow:

"Delays the program execution for the given number of seconds."

but problem is it actually delays execution of all the scripts running on the server.

so if we run the attached Test Script 10 times in parallel. it'll take 20 seconds to complete all the requests. Please fix the words in documetation.


Thanks :)

Test script:
---------------
<?php

sleep(2);
echo "Hello";


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-02-26 04:35 UTC] keithm at aoeex dot com
Sleep does not block other instances of the script.  Here's a snippet of ab output using your test script:

---
Concurrency Level:      10
Time taken for tests:   4.246 seconds
Complete requests:      10
---

All 10 requests were completed in just 4.246 seconds.

You probably have some other element causing your scripts to depend on each other which is then causing a sleep in one script to delay the others.  

For example if your scripts all use sessions this can happen. With the default file-based sessions, calling session_start() will lock the session file. Any other scripts trying to call session_start() referencing that same file will block until the first script closes the file by either terminating or calling session_write_close(). So calling sleep() in a script that is using the session would cause other scripts to be delayed by the sleep duration due to the lock on the session file, not due to how sleep() works.
 [2014-02-26 09:35 UTC] aryans dot vinay at gmail dot com
-Status: Open +Status: Closed
 [2014-02-26 09:35 UTC] aryans dot vinay at gmail dot com
Thank You for the quick reply. Actually if we run the same script in 10 different tabs in one browser time of every sleep will add up!
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 08:00:02 2026 UTC