是否有任何方法对PHP对象方法进行异步调用?使用jquery,我可以将.load en外部文件放到div中,但这样我就无法访问下面的setTemp这样的方法。我希望避免在启动第二次更新之前,“等待”一个对象更新。
我的尝试(失败)如下,三个文件:
海滩登记簿:
<!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>Baiadosancho.php
class Baiadosancho{
private $temp;
public function getTemp() {
return $this->temp;
}
public function setTemp() {
// $json = file_get_contents('urltogettemperature');
// $arrayDecodedFromJSON = json_decode($json, true);
// ...
// $this->temp = $arrayDecodedFromJSON['temp'];
}
}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'];
}
}..I还考虑了其他方法,如下面的方法,它们对你有好处吗?
GearMan,PHP、EvPeriodic和iron.io中的并行cURL执行
发布于 2014-08-09 23:33:25
我的问题的答案如下:
正如deceze所写的:如果您想要异步执行(在标准PHP中),那么您将不得不求助于类似Gearman或可能是分叉的东西。标准PHP是单线程的,而不是偶发的。
尽管可以使用jquery,但是如何从请求的文件访问对象将在这里解释:Using objects in Ajax calls PHP files
https://stackoverflow.com/questions/25141856
复制相似问题