If you want to make the terminal beep on a PHP CLI application without needing the ncurses library, use the following code:
<?php
function cli_beep()
{
echo "\x07";
}
?>
(PHP 4 >= 4.0.7, PHP 5 < 5.3.0, PECL ncurses >= 1.0.0)
ncurses_beep — Let the terminal beep
此函数是实验性的。此函数的表象,包括名称及其相关文档都可能在未来的 PHP 发布版本中未通知就被修改。使用本函数风险自担。
ncurses_beep() sends an audible alert (bell) and if its not possible flashes the screen.
If you want to make the terminal beep on a PHP CLI application without needing the ncurses library, use the following code:
<?php
function cli_beep()
{
echo "\x07";
}
?>
arplynn's function has a subtle bug, if it's being called while ob_start()'s output buffering is active, it does not make the system beep, and worse, it may corrupt whatever data is being generated under OB, by inserting an unprintable ascii character in it. use fprintf to STDOUT to bypass OB, eg
<?php
function cli_beep() {
fprintf ( STDOUT, "%s", "\x07" );
}