douya2982 2018-05-28 01:26
浏览 27

线程PHP中的Sleep()

I have a PHP script where I create several threads with the pthread library. In these threads I use the sleep() function. The problem is that sleep() pause my main thread. So I lose all the advantage of making threads...

Does anyone have a way to pause my threads without pausing my main thread?

This threaded class call another php script where the sleep is.

class CallAgent extends Thread
{

private $id_com;
private $agt_id;
private $pat_id;
/**
 * CallAgent constructor.
 */
public function __construct($id_com, $agt_id, $pat_id)
{
    $this->id_com = $id_com;
    $this->agt_id = $agt_id;
    $this->pat_id = $pat_id;
}

public function run()
{
    echo shell_exec("C:\\xampp\php\php.exe -f C:\\xampp\htdocs\call_script.php -- " .$this->id_com. " " .$this->agt_id. " " .$this->pat_id);
}
}

This is the script called by the thread.

function run($id_com, $agt_id, $pat_id)
{
$bdd = new bdd();
$bdd->connect();
$decision = rand(0, 100);
if ($decision >= 2) {
    echo "L'agent à décrocher et rentre en com avec un patient
";
    $bdd->update_etat_com($id_com, "decrocher");
    $bdd->update_agt_etat($agt_id, "com");
    $bdd->update_pat_etat($pat_id, "OUT");
    sleep(8);
    echo "Call finished.
";
    $bdd->update_agt_etat($agt_id, "repos");
}
else {
    $bdd->update_dispo_agt($agt_id, "indisponible");
    echo "Timeout Agent.
";
}
}

Thanks in advance.

展开全部

  • 写回答

0条回答 默认 最新

      编辑
      预览

      报告相同问题?

      手机看
      程序员都在用的中文IT技术交流社区

      程序员都在用的中文IT技术交流社区

      专业的中文 IT 技术社区,与千万技术人共成长

      专业的中文 IT 技术社区,与千万技术人共成长

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

      客服 返回
      顶部