-2

在运行脚本之前是否可以等待 20 秒?

我的意思是我尝试 set_time_limit(20) 但是当我单击按钮时,它总是运行脚本。

我猜时间限制只是脚本运行时的时间限制,然后它将停止。

我正在寻找一个可以帮助我的脚本等待 20 秒的函数。我知道它可以在 jQuery 上运行,但我认为正确的是 Yii 框架。

我有下面的示例脚本

$coco = mysql_query( "SELECT * FROM gameWaiting" );
if ( empty( $coco ) ) {
mysql_query( "INSERT INTO gameWaiting VALUE('', '$email', '$language')" );
$status = 0; // IF THE STATUS is equal to 0 means the db was empty so it will insert
// AND WAIT FOR OTHER PLAYER TO INSERT ALSO
} else {
mysql_query( "INSERT INTO gameWaiting VALUE('', '$email', '$language')" );
$status = 1; // IF THE STATUS is equal to 1 means the db was !empty so it will insert also
// BUT THERE is no need to wait for other player otherwise RAND() the user.
}

// NOW SET TIME HERE when it will INSERT to the game
if ( time was equal to set) {
// IF SOMEONE insert into gameWaiting it will create game
mysql_query( "INSERT INTO game VALUE('','name','email','language')" );
} else {
// No player was added
}

echo $status;

我希望这是可能的...

4

3 回答 3

4

set_time_limit()指定脚本的最大执行时间,而不是等待执行它的时间(请参阅Docs)。

您可以使用 PHP 的sleep()函数强制执行延迟给定的秒数:

sleep(20); 
于 2012-10-02T10:41:49.917 回答
3

sleep()您可以使用函数暂停脚本。

sleep(20)

确保set_time_limit高于此

于 2012-10-02T10:41:24.707 回答
1

试试这个 php

sleep(10);

根据需要替换 10

于 2012-10-02T10:41:39.997 回答