PHP Die()
die() will stop executing the php code and exit. It must have a message as parameter which will be printed before exit.
<?PHP
if ($_POST['ex'] == "") die ("Information not provided!");
?>
die() is usually used in database connection, if not connected, then stop executing the code.
<?PHP
$connect = mysql_connect ("$host", "$user", "$pass") or die (mysql_error());
mysql_select_db("$dbs",$connect) or die (mysql_error());
?>
exit or exit() can be used to stop the PHP program. It is almost equivalent to die().
It is better to use exit to stop the program if running in command line mode.
<?PHP
...
exit;
?>
sleep(x) can be used to delay the PHP program for x seconds. e.g. to delay a thread in a multi-threads program.
<?PHP
sleep(2); //delay 2 seconds
?>