phpwebdriver selenium等待ajax

I using selenium with phpwebdriver, I think so its not phpUnit, anyway I am going to load a page that has ajax load and I want to wait until ajax load compelete, I need to get getPageSource complete.

require_once "phpwebdriver/WebDriver.php";

$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");                            
$webdriver->get("http://www.hoopabooks.ir/%DA%A9%D8%AA%D8%A7%D8%A8-%D9%87%D8%A7%DB%8C-%D8%AE%D9%88%D8%B1%D8%AF%D9%86%DB%8C");         

$element = $webdriver->getPageSource();
echo ($element);

This is my solution for PHPUnit_Extensions_Selenium2TestCase

/**
 * waitUntil(callback, timeout)
 * callback - will be called in a loop until return non null value or timeout
 *
 * executeAsync(array(string script, array arguments))
 * executeAsync returns arguments of default arguments[0] function when arguments[0] is called.
 * A bit strange, maybe there is another solution to pass the value from browser's js environment.
 */
protected function waitForAjaxComplete()
{
    $driver = $this;
    $this->waitUntil(function() use($driver) {
        $condition = 'arguments[0].call(null, $.active == 0)';
        if($driver->executeAsync(array(
            'script' => $condition,
            'args' => array()
            ))
        )
            return true;
    }, 10000);
}

I'm pretty sure it can be easily converted to the facebook/php-webdriver code