public function download($url, callable $onComplete = null)
    {
        //first check if the function is called external
        if($this->isExternal())
        {
            $data = file_get_contents($url);
            //hold the process to simulate more to do ;-)
            sleep(3);
            echo "Downloaded: ".strlen($data).' bytes from url: '.$url.PHP_EOL;
            //return the data
            //parent thread can handle this if needed
            return $data;
        }
        else
        {
            //we are in the parent context
            //just redirect to the thread
            //we use async as we dont want to wait for the result
            //return the handle allow the caller to check result
            return $this->asyncCallOnChild(__FUNCTION__, array($url), $onComplete);
        }
    }
public function download($url, callable $onComplete = null)
    {
        //first check if the function is called external
        if($this->isExternal())
        {
            $data = file_get_contents($url);
            //hold the process to simulate more to do ;-)
            sleep(3);
            echo "Downloaded: ".strlen($data).' bytes from url: '.$url.PHP_EOL;
            //return the data
            //parent thread can handle this if needed
            return $data;
        }
        else
        {
            //we are in the parent context
            //just redirect to the thread
            //we use async as we dont want to wait for the result
            //return the handle allow the caller to check result
            return $this->asyncCallOnChild(__FUNCTION__, array($url), $onComplete);
        }
    }
public function download ( $ url , callable $ onComplete = null ) { //first check if the function is called external
 if ( $ this -> isExternal ( ) ) { $ data = file_get_contents ( $ url ) ; //hold the process to simulate more to do ;-)
 sleep ( 3 ) ; echo "Downloaded: " . strlen ( $ data ) . ' bytes from url: ' . $ url . PHP_EOL ; //return the data
 //parent thread can handle this if needed
 return $ data ; } else { //we are in the parent context
 //just redirect to the thread
 //we use async as we dont want to wait for the result
 //return the handle allow the caller to check result
 return $ this -> asyncCallOnChild ( __FUNCTION__ , array ( $ url ) , $ onComplete ) ; } }
Function for downloading urls external
@param string $url
@param callable $onComplete
@return AsyncMessage|string
Function for downloading urls external