Gegroet iedereen. Ik gebruik op dit moment het volgende:

	$url = sprintf("http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=%s&steamids=%s",
		$api_key,
		$steam_id);

	$curl_time = microtime(1);
	// Needs curl to actually be able to pull data from steam api because of the special response-behaviour.
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    @curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 5 );
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 3  ); #rc1: helps with page delay if steam is down
    $raw_json = curl_exec( $ch );
    $http_response_header = curl_getinfo( $ch );
	$curl_errno = curl_errno($ch);
	$curl_error = curl_error($ch);
	curl_close($ch);
    
    $url = sprintf("http://api.steampowered.com/IPlayerService/GetSteamLevel/v0001/?key=%s&steamid=%s",
		$api_key,
		$steam_id);

	$curl_time = microtime(1);
	// Needs curl to actually be able to pull data from steam api because of the special response-behaviour.
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    @curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 5 );
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 2 ); #rc1: helps with page delay if steam is down
    $steamlevel = curl_exec( $ch );
    $http_response_header = curl_getinfo( $ch );
	$curl_errno = curl_errno($ch);
	$curl_error = curl_error($ch);
	curl_close($ch);
    
    $steamlevel = json_decode($steamlevel, 1);



	// Get Player Bans API
	    
	    $url = sprintf("http://api.steampowered.com/ISteamUser/GetPlayerBans/v1/?key=%s&steamids=%s",
		$api_key,
		$steam_id);

	$curl_time = microtime(1);
	// Needs curl to actually be able to pull data from steam api because of the special response-behaviour.
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    @curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 5 );
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 2 ); #rc1: helps with page delay if steam is down
    $tradeban = curl_exec( $ch );
    $http_response_header = curl_getinfo( $ch );
	$curl_errno = curl_errno($ch);
	$curl_error = curl_error($ch);
	curl_close($ch);
    
$tradeban = json_decode($tradeban, 1);

	// END Get Player Bans API


	// Get Item Info API //
	    
	$url = sprintf("http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=%s&steamid=%s",
	$api_key,
	$steam_id);

	$curl_time = microtime(1);
	// Needs curl to actually be able to pull data from steam api because of the special response-behaviour.
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $url );
    @curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
    curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
    curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false );
    curl_setopt( $ch, CURLOPT_MAXREDIRS, 5 );
    curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 2 ); #rc1: helps with page delay if steam is down
    $getplayeritems = curl_exec( $ch );
    $http_response_header = curl_getinfo( $ch );
	$curl_errno = curl_errno($ch);
	$curl_error = curl_error($ch);
	curl_close($ch);
    
        $getplayeritems = json_decode($getplayeritems, 1);

	// END Get Item Info API //


Ik merk op dat door vele API's te gebruiken van steam, dat het laden van de pagina echter lang duurt. Ik probeer dit dus te combineren in 1 code, i.p.v. 4x een curl_close($ch);. Met hopelijk dat ik een optimized code kan gebruiken om de laad-tijd te verbeteren. Met PHP ben ik nog nieuw, dus ik doe mij best :).

Wie kan mij hierbij helpen? Ik heb al verschilende soorten curl's geprobeerd, maar het lukt me maar niet.
Je wilt 4 URLs binnen halen.
Dat moet gewoon met 4 acties.

Normaal kan dat ook met file_get_contents(), maar dat zal niet werken, gezien deze regel (regel 79 onder andere):
<?php
    // Needs curl to actually be able to pull data from steam api because of the special response-behaviour.
?>


Je hebt dus 4 accties nodig.
Al kan je wel af met (veel) minder code.
Voor de rest ziet het er prima uit.

Wat is het probleem?
Je kan de curl-close() ook gewoon weghalen... dan blijft je connectie open.
Dat kan handig zijn als je inlogt ergens (actie 1), dan een pagina opent (actie 2) en daarna iets wil plaatsen (actie 3).
CURL is handig voor dat soort dingen, want je kan ook cookies/sessies etc krijgen tijdens je bezoek die je dan 'onthoudt'.
Het probleem is dat op dit moment, dat de pagina laadtijd te langzaam is (8 tot 10 seconden). Denk omdat ik misschien teveel API's heb toevoegt. Het is voor een forum, elke keer als een thread word geopend, checkt ie de API voor elke member in die thread en slaat ie per member op in een cache bestand. bijv:

a:11:{s:7:"steamid";s:17:"76561197994195927";s:24:"communityvisibilitystate";s:1:"3";s:11:"personaname";s:13:"MasterSoprano";s:10:"profileurl";s:39:"http://steamcommunity.com/id/MrSoprano/";s:6:"avatar";s:116:"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/a1/a101f855bceb7cf565482632fbc3d310b5dd4bc3.jpg";s:12:"avatarmedium";s:123:"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/a1/a101f855bceb7cf565482632fbc3d310b5dd4bc3_medium.jpg";s:10:"avatarfull";s:121:"https://steamcdn-a.akamaihd.net/steamcommunity/public/images/avatars/a1/a101f855bceb7cf565482632fbc3d310b5dd4bc3_full.jpg";s:11:"timecreated";s:10:"1195099352";s:12:"player_level";i:29;s:10:"EconomyBan";s:4:"none";s:15:"backpack_status";i:1;}


Dat terwijl ik de thread zo heb ingesteld dat ie maar 5/10 posts per pagina laat zien duurt het alsnog te lang.

Zie: http://pastebin.com/LUkzbfAv voor de hele code.
Je slaat het wel op in de cache, maar gebruik je die ook?
Als je zegt dat je elke keer als een thread wordt geopend, de API checkt.
Dat moet je dus niet doen: je moet de cache openen.

En op de achtergrond (of eens per 10 minuten oid) de cache bijwerken.
Daar merken je gebruikers/bezoekers niets van, want zij hoeven niet te wachten.
Excuses :), de cache is 1 dag geldig. Zodra er een cache is van die gebruiker, zal de thread ook echter veel sneller laden. Het probleem is hier echter dat als er geen info van meerdere gebruikers per thread is, het (vind ik) vrij lang duurt voordat alle gegevens word aangemaakt. Bijv, een thread van 10 posts duurt ongeveer 6 tot 10 seconden voordat alle API's zijn doorgelezen en cache files zijn aangemaakt. En dan ga ik hiervan uit dat op die gehele pagina geen enkele API gegevens 'nog' beschikbaar zijn voor de gebruikers.

Na die dag zal een cron alle cache checken om te zien wat er "out-of-date" is, en behouden en of verwijderen.

Reageren