2016-08-01 48 views
0

Ich entwickelte ein Skript mit PHP, die ich mit der Konsole verwenden, mit dem Befehl php index.php.Zeigen Sie keine Protokolle mit PHP-Befehl und cURL

In diesem Skript verwende ich cURL, um einen Server abzufragen.

Das Problem ist mein Skript zeigt Protokolle auf der Konsole, und ich möchte nur das Ergebnis des Echos.

Haben Sie eine Idee, diese Protokolle zu verbergen?

// GET TOKEN 
// ///////////////////////////////////////////////////////////////////////////// 
$url = "some/url"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_USERPWD, "$user:$pwd"); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, 1); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
$data = curl_exec($ch); 
$location = ""; 
preg_match_all('/^Location:(.*)$/mi', $data, $location); 
$location = trim($location[1][0]); 
$location = parse_url($location); 
parse_str($location['query'], $attrs); 
$token = $attrs['code']; 

if(isset($token)) { 

    // GET CONNEXION 
    // ///////////////////////////////////////////////////////////////////////// 
    $url = "some/url"; 
    $post_data = ['code' => $token, 'grant_type' => 'authorization_code']; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_USERPWD, "$client_id:$client_secret"); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    $data = json_decode(curl_exec($ch)); 
    $connexion = isset($data->access_token) ? $data->access_token : $data->error_description; 

    // GET LOGIN 
    // ///////////////////////////////////////////////////////////////////////// 
    $url = "some/url"; 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    $data = curl_exec($ch); 
    $data = json_decode($data); 
    // $login = json_encode(['public' => $data->api_keys[1]->public, 'secret' => $data->api_keys->secret]); 

    // REQUEST 
    // ///////////////////////////////////////////////////////////////////////// 
    $url = $request . "?externalId=".$external_id."&externalSource=".$external_source; 
    date_default_timezone_set("Europe/Paris"); 
    $nonce = generateRandomString(); 
    file_put_contents('php://stderr', print_r("Set random nonce to " . $nonce . "\n", TRUE)); 
    $created = date("Y-m-dTH:i:sP"); 
    $created = date("Y-m-dTH:i:sP"); 
    $username = $data->api->public; 
    $secret = $data->api->secret; 
    $pwd_digest = base64_encode(sha1($nonce.$created.$secret)); 
    $auth_header = "X-WSSE: UsernameToken Username=\"$username\", PasswordDigest=\"$pwd_digest\", Nonce=\"$nonce\", Created=\"$created\""; 
    $header = array($auth_header, 'Accept: something', 'Accept-Language: en'); 
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 
    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    $data = curl_exec($ch); 
    $data = json_decode($data); 
    echo $data->nbNqPoints; 

} else { 
    echo "0"; 
} 
+0

Denn mit jeder Website, die wir mit jeder Art und Weise verarbeiten müssen. So können Sie Ihre $ url und jede mögliche Sache zur Verfügung stellen, die Sie zur Verfügung stellen können, also können wir Ihnen helfen! –

+0

Ich weiß nicht, ob es verwandt ist oder nicht, aber wo Sie CURLOPT_RETURNTRANSFER setzen, versuchen Sie, es auf "true" statt auf 1 zu setzen. –

+1

Sie könnten ein wenig ob_start(); ob_get_clean(); hack, um durchzukommen – hanshenrik

Antwort

0

Antwort unter dieser Adresse: managing curl output in php

ich diese Zeile für jedes cURL Beispiel:

curl_setopt($ch, CURLOPT_VERBOSE, 0);