Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP对对象方法的异步调用_Php_Oop_Asynchronous_Methods_Call - Fatal编程技术网

PHP对对象方法的异步调用

PHP对对象方法的异步调用,php,oop,asynchronous,methods,call,Php,Oop,Asynchronous,Methods,Call,有没有办法对PHP对象方法进行异步调用?使用jquery,我可以将en外部文件加载到div中,但这样我就无法访问下面的settmp方法。我希望避免在启动第二次更新之前必须等待一个对象更新 我失败的尝试如下所示,三个文件: 海滩登记员: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>OO Method test</title> &

有没有办法对PHP对象方法进行异步调用?使用jquery,我可以将en外部文件加载到div中,但这样我就无法访问下面的settmp方法。我希望避免在启动第二次更新之前必须等待一个对象更新

我失败的尝试如下所示,三个文件:

海滩登记员:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>OO Method test</title>
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script>
        $(document).ready(function() {
            setInterval(function() {
                $("#BaiadoSancho").load();
            }, 60000);
        });

        $(document).ready(function() {
            setInterval(function() {
                $("#GraceBay").load();
            }, 60000);
        });

    </script>
</head>

<body>
    <?php
    include 'Baiadosancho.php';
    include 'Gracebay.php';

    $baia = new Baiadosancho;
    $baia->setTemp();

    $grace = new Gracebay;
    $grace->setTemp();

    // .... lots of other beaches
    ?>

    <div id = "BaiadoSancho">
        <?php $baia->setTemp(); ?>
    </div>

    <div id = "GraceBay">
        <?php $grace->setTemp() ?>
    </div>

</body>
</html>
Gracebay.php
class Gracebay {

private $temp;

public function getTemp() {
    return $this->temp;
}

public function setTemp() {
//        $json = file_get_contents('sampl/temperature');
//        $arrayDecodedFromJSON = json_decode($json, true);
//        ...
//        $this->temp = $arrayDecodedFromJSON['temp'];


}

}
…我也考虑过其他方法,比如下面的方法,你认为它们有利吗


GearMan,PHP、EVP和iron.io中的并行cURL执行我的问题的答案如下:

正如德塞兹所写: 如果您希望在标准PHP中异步执行,那么您将不得不求助于Gearman或可能的forks之类的工具。标准PHP是单线程的,没有事件

不过,可以使用jquery,下面解释了如何从请求的文件访问对象:

为什么要使用带括号的新gracebay和不带括号的新baiadosancho?如果您想要异步执行,那么您必须使用Gearman或forks之类的工具。标准PHP是单线程的,没有事件。@MrJack只是一个错误,已更正,谢谢you@deceze恐怕是这样。不过,我还是希望jquery能够实现这一点。使用下面的代码,我可以加载一个文件并将其内容加载到div中,这不是异步的吗?下面代码的问题是$baia和$grace对象和方法不适用于filetoload.php$document.readyfunction{setIntervalfunction{$BaiadoSancho.loadfiletoload.php;},300000;};如果您从客户端调用这些操作,那么是的,您可以并行发出多个请求,这些请求将异步运行,就像从客户端看到的那样。然而,正如我理解您的问题,您希望PHP启动此类异步任务,在这种情况下,请参见上面的注释。
class Gracebay {

private $temp;

public function getTemp() {
    return $this->temp;
}

public function setTemp() {
//        $json = file_get_contents('sampl/temperature');
//        $arrayDecodedFromJSON = json_decode($json, true);
//        ...
//        $this->temp = $arrayDecodedFromJSON['temp'];


}

}