lundi 19 décembre 2016

Laravel scheduler throwing error on executing xml_decode()

I'm using Laravel 5.3 and I have this line under schedule() function in App\Console\Kernel.php.

$schedule->call('App\Http\Controllers\Controller@fetchXmlRpcResult')->everyMinute();

The function is sort of tedious but the jist of it: get the timestamp of the last record found in the database, create a new XML-RPC request asking for new records with start_date of the 'last found timestamp in the DB', decode the XML-RPC result and insert into the DB.

public static function fetchXmlRpcResult($user, $password, $account_id, $date)
    {
        $client = new Client('http://ift.tt/2i8PfZG');
                $client->setSSLVerifyPeer(false);
                $client->setSSLVerifyHost(2);
                $client->setCredentials($user, $password, CURLAUTH_DIGEST);

                $parameters = [removed]
                $request = new Request('getAccountData', $parameters);

        $response = $client->send($request);

        // removing the 401 HTTP Unauthorized header
        $xml = (substr($response->raw_data, strpos($response->raw_data, "\r\n\r\n")+4));

        // removing the OK HTTP header
        $xml2 = (substr($xml, strpos($xml, "\r\n\r\n")+4));

        $accountCDRs = xmlrpc_decode($xml2);

        return $accountInfo;
    }

When I run php artisan schedule:run in the console, I'm prompted with this error:

Running scheduled command: App\Http\Controllers\Controller@fetchXmlRpcResult

XML-RPC: PhpXmlRpc\Helper\Http::parseResponseHeaders: HTTP error, got response: HTTP/1.1 401 Unauthorized


  [Symfony\Component\Debug\Exception\FatalThrowableError]
  Call to undefined function App\Helpers\xmlrpc_decode()

The controller uses the file in App\Helpers\XmlHandler.php and in that file I use the following classes:

use PhpXmlRpc\Value;
use PhpXmlRpc\Request;
use PhpXmlRpc\Client;

Could the HTTP response be throwing it out? I tried executing the same function via the browser (aka putting the function in the route.php under http://ift.tt/RUrgiZ) and it worked perfectly fine.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire