我有一个简单的function1,它向google api发出http请求并返回$ result.然后我有另一个函数2,如果$ result isset,应该使用$ result进行一些计算,然后返回$ finalresult..
我的问题是,对google api的调用需要几秒钟,而当function1返回$ result时,function2已经返回$ finalresult而不考虑$ result.
我要做的是让function1完全运行并在function2开始之前返回$ result.
我正在寻找一种不仅仅使用"sleep()"的解决方案,因为这个函数不能保证实际返回$ result.(除非有某种方法可以循环睡眠(1)直到$ return isset,或类似的东西)
视觉女孩和男人的示例代码
function1_geocode($address); // this function makes a http request to google and returns $result
function2_proximitysearch(){
if (isset($result)){
//inevitably by the time the script gets there, $result hasn't been returned yet therefore none of the "some stuff" code is executed.
//some stuff
}
else {
//some other stuff
}
}
Run Code Online (Sandbox Code Playgroud)