PHP中的Ajax

I know AJAX will not be what it is called, but I am looking for something similar that can be done from within PHP itself (not using javascript).

Basically, as the PHP is creating the page, I want to query an API to gather some information that will be used on the current page. Is this possible, and if so what would be the best method?

Thanks

You can use fopen or curl:

Here is an example to open a connection to twitters API, read the public timeline and output parts of it.

<?php
$fp = fopen("http://api.twitter.com/1/statuses/public_timeline.json?count=3&include_entities=false","r");
while($data = fgets($fp))
{
    $json .= $data;
}
$arr = json_decode($json);
print_r($arr);
?>

If you're talking about a remote HTTP API, you would utilize cURL at runtime. It's basically PHP's way of accessing information across domains.

The above can be a little overwhelming - check out the simple example page to get you started. If available, I suggest working with cURL from the command line, as there's quite a few options on there. It's a good way to get familiar with the command and different options available.

You are probably wanting curl.

http://php.net/manual/en/book.curl.php