绝对不是同步与异步的问题.但是调试是非常不可能的.尝试这样的事情.死亡陈述很难看,但说明了你可能希望合并的验证……
$data = file_get_contents("http://example.com/aaa.php?user=tester&akey=abcdef1234");
if (empty($data)) die('Failed to fetch data');
$dec = json_decode($data, true);
if (is_null($dec) || $dec === false) die('Failed to decode data');
$tokenid = isset($dec['message']['result']['tokenid']) ? $dec['message']['result']['tokenid'] : null;
if (is_null($tokenid) die('Token ID is not set');
//...
$data=file_get_contents("http://example.com/bbb.php?user=tester&token=".$tokenid);
猜测可能是您的令牌有时包含需要转义的“特殊”字符.