PHP | die() & sleep() functions Last Updated : 11 Apr, 2022 Comments Improve Suggest changes Like Article Like Report die() The die() is an inbuilt function in PHP. It is used to print message and exit from the current php script. It is equivalent to exit() function in PHP. Syntax : die($message) Parameters : This function accepts only one parameter and which is not mandatory to be passed. $message : This parameter represents the message to printed while exiting from script. Return Value : It has no return value but prints given message while exiting the script. Examples : Input : die("code ends here") Output : code ends here Here, die() function ends the script with a message "code ends here " Applicable versions : This function is applicable in all PHP4 and later versions. Program : PHP <?php // blank url of site // so that die() is executed $site = ""; // open url else die (exit) fopen($site, "r") or die("Unable to connect to given site."); ?> Output : Unable to connect to given site.sleep() The sleep() is an inbuilt function in PHP. It is used to delay the execution of the program for given amount of seconds. Syntax : int sleep(int $seconds) Parameters : This function accepts only one parameter and which is mandatory to be passed. $seconds : This parameter represents the delay time in seconds. Return Value : It returns zero on success, or FALSE on error. This function returns a non-zero value if the call was interrupted by a signal. Errors / Exceptions : This function generates E_WARNING when the number of seconds is negative. Applicable versions : This function is applicable in PHP 4, PHP 5, PHP 7. Program : PHP <?php // initial timings echo date('h:i:s') . "\n"; // halt for 5 seconds sleep(5); // timings after halt echo date('h:i:s'); ?> Output : 01:07:16 01:07:21 Note that, Timing after halt (sleep) is 5 seconds more than timings before halt (sleep). References: http://php.net/manual/en/function.die.php http://php.net/manual/en/function.sleep.php Let us see both the functions in a Tabular form -: die() Functionsleep() Function1.The die() function is an alias of the exit() functionThe sleep() function is used to delay the execution of the script some time.2.It takes a parameter as a NumberIt takes a parameter as a Number ( Time in seconds )3.It does not have any return valueThe number in Parameter cannot be negative it will also be positive4.It is supported in PHP version 4+It returns a value that is True or False5.The die() function is used to print the message.It is supported in PHP version 4+ Comment More infoAdvertise with us Next Article PHP | die() & sleep() functions P Prasad_Kshirsagar Follow Improve Article Tags : Misc Web Technologies PHP PHP-function Practice Tags : Misc Similar Reads PHP | sleep( ) Function The sleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for a specified number of seconds. The sleep( ) function accepts seconds as a parameter and returns TRUE on success or FALSE on failure. If the call is interrupted by a signal, sleep() funct 2 min read PHP | usleep( ) Function The usleep() function in PHP is an inbuilt function which is used to delay the execution of the current script for specific microseconds. It is similar to the sleep() function which delays execution of the current script for a specified number of seconds, unlike the usleep() function which delays th 2 min read PHP SplQueue::dequeue() Function The SplQueue::dequeue() function is an inbuilt function in PHP which is used to dequeues the node from the queue. Syntax: mixed SplQueue::dequeue() Parameters: This function does not accept any parameter. Return Value: This function return the value of the dequeued node. Below programs illustrate th 1 min read PHP define() Function The define() function is basically used by programmers to create constant. Constants in PHP are very similar to variables and the only difference between both are the values of constants can not be changed once it is set in a program. define() returns a Boolean value. It will return TRUE on success 2 min read PHP | call_user_func() Function The call_user_func() is an inbuilt function in PHP which is used to call the callback given by the first parameter and passes the remaining parameters as argument. It is used to call the user-defined functions. Syntax: mixed call_user_func ( $function_name[, mixed $value1[, mixed $... ]]) Here, mixe 2 min read PHP | Functions A function in PHP is a self-contained block of code that performs a specific task. It can accept inputs (parameters), execute a set of statements, and optionally return a value. PHP functions allow code reusability by encapsulating a block of code to perform specific tasks.Functions can accept param 8 min read PHP Arrow Functions PHP arrow functions are a shorthand syntax for anonymous functions. It was introduced in PHP 7.4, which provides a shorter way to write anonymous functions. They allow you to create functions with fewer lines of code while maintaining functionality. They provide an easy-to-read syntax, particularly 5 min read PHP | zip_close( ) Function The zip_close() function is an inbuilt function in PHP which is used to close a zip archive file opened by the zip_open() function. The zip_close() causes the stream to be closed and the connection to the corresponding Zip Archive to be broken. The zip resource which has been opened by the zip_open( 2 min read PHP | time_sleep_until( ) Function The time_sleep_until() function in PHP is an inbuilt function which is used to delay execution of the current script until the specified time. The time_sleep_until( ) function accepts timestamp as a parameter and this timestamp denotes when the script should wake. The time_sleep_until( ) function re 2 min read Like