![]() The sleep() function will always return a NULL (in the Windows platform, before PHP 5.3.4) if that particular script has a sleep occurred, irrespective of whether the function was previously interrupted or not.When the seconds' parameter is passed with a negative value, this function usually generates an E_WARNING.When there is an interrupted call by a signal, the sleep()will return a non-zero value.Let's discuss various scenarios when these exceptions and errors pop up. If certain circumstances arise when using this function, it can cause exceptions. Exceptions, Errors, and Different Scenarios Encountered by Sleep() Function The seconds' parameter is a mandatory one, and one must specify the value for using this function. If the number of seconds is given in negative, then this function will throw an error. Here, seconds is where you have to specify the number of seconds for which your current script will delay its execution. In other operating systems, this function will return the number of seconds that is left to sleep. If you are a Windows user, your value will always appear to be 192 that is actually the value of WAIT_IO_COMPLETION. This function takes the number of seconds as its parameter and will return TRUE if it succeeds and FALSE when a failure occurs.Ī non-zero value will be returned when the call gets interrupted by a signal. Sleep() function is one of the important built-in functions provided by PHP version 4.0 or above to delay any script's execution process for a certain time interval. In this tutorial, you will learn about the sleep() function that helps delay any PHP script execution. This has become possible because of the powerful systems coming in these days and your computer's ability to perform multiprogramming. Here is the code.PHP Overview PHP Tutorial PHP Introduction PHP Installation PHP Basics PHP Basics PHP Syntax PHP Data Types PHP Variables PHP Constants PHP Print and Echo Statements Operators PHP Operators PHP Arithmetic Operators PHP Assignment Operators PHP Comparison Operators PHP Logical Operators PHP Ternary Operator PHP Concatenation Operators Decision Control Structures PHP Decision Making PHP if else statement PHP elseif statement PHP switch statement Loop Control Structures PHP Looping PHP while loop PHP do-while PHP for loop PHP foreach loop Functions PHP Date and Time PHP Functions PHP String Handling Functions PHP Include and Require PHP Headers PHP File Handling PHP Cookies PHP Sessions PHP Sending Emails Compare Strings In PHP array_diff() Function in PHP array_merge() Function in PHP array_search() Function in PHP eval() in PHP preg_replace() Function in PHP URL Encoding and Decoding with PHP sleep() Function in PHP strlen() Function in PHP ksort() Function in PHP strlen() Function in PHP gettype() Function in PHP Forms PHP GET and POST PHP Server Side Form Validation PHP File Upload PHP Classes and Objects PHP OOP Terminology PHP Access Modifiers What is stdClass in PHP? PHP Inheritance PHP OOP Traits PHP Abstract Classes PHP Constructor PHP Destructor Miscellaneous PHP Arrays PHP RSS Feed PHP Composer Environment Variables in PHP PHP Error HandlingĪs you all know that modern computer programming allows us to execute multiple scripts simultaneously. Then the sleep command will delay the execution by 15 seconds and then again we will print the server time to see the delay. Here we will first display the time in hour : minute : second format and then use the php flush command to send the output to browser. Let us print the time after a delay of 15 seconds. This setting you can know by increasing the sleep time till the set value of execution time at server. Say you want to see maximum script execution time of your server. Some time while testing our scripts we need to add some delay, here it is useful. The above command will create a delay of 25 seconds, the next step of execution will be after the delay of 25 seconds. This command sleep will delay the output by seconds specified in sleep command. We can create a delay by using sleep command inside our PHP script. ![]() Using sleep to add delay or increase execution time ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |