Hoi,
Nadat ik voor een webradio het aantal luisteraars via een cache.txt weergeef moest ik dit van de "radio-provider" ook doen voor het huidige nummer.. Alleen wanneer ik alles invoer komt er in de cache file voor het huidige nummer de one2xs host pagina te staan.. Ik voeg 3 linkjes bij zodat jullie kunnen zien wat het geval is! Ik zal hieronder ook het call_api.php script bijvoegen! Iemand enig idee hoe ik dit kan fixen? Beloning 0.1 voor de goede oplossing.
Bij de luisteraars API werkt alles prima en wordt er goed gecached! De cache files zijn allemaal 777.
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Votre RadioUID
$radiouid = "0be958e7-3925-4cba-98d0-d8517550e9bb";
// Votre APIKey
$apikey = "////geheim////";
// Récupération des pochettes
$cover = "no"; // "yes" ou "no"
/* --------------------------------- */
/* #### ! NE PAS MODIFIER ! #### */
/* --------------------------------- */
// Fichier de cache local
$cache = ./cache_api.txt;
$cacheCall = ./cache_callapi.txt;
$date = "-1";
// Test des droits daccès
if(substr(decoct(@fileperms($cacheCall)),3, 3) != "777" && substr(decoct(@fileperms($cacheCall)),3, 3) != "644" && !@chmod($cacheCall, 0777)){
echo Erreur ! Vous devez autoriser en écriture le fichier cache_callapi.txt;
exit;
}
if(substr(decoct(@fileperms($cache)),3, 3) != "777" && substr(decoct(@fileperms($cache)),3, 3) != "644" && !@chmod($cache, 0777)){
echo Erreur ! Vous devez autoriser en écriture le fichier cache_api.txt;
exit;
}
if($lines = file($cacheCall)){$date = (isset($lines[1]) ? $lines[1] : -1); $time = $lines[0]; $expire = time() - $time;}
else{$expire = time() - 1;}
if(@file_exists($cache) && $date > $expire && file_get_contents($cache) != ""){ echo file_get_contents($cache);}
else{
@file_put_contents($cacheCall, "200"."
".time());
$context = stream_context_create(array(http => array(timeout => 30)));
touch($cache);
$xml = @file_get_contents(http://api.radionomy.com/currentsong.cfm?radiouid=.$radiouid.&callmeback=yes&type=xml.(!empty($apikey) ? &apikey=.$apikey : )..(!empty($cover) ? &cover=.$cover : ).,0, $context);
if(!$xml)
$xml = @simplexml_load_file($cache);
else{
@file_put_contents($cache, $xml);
$xml = @simplexml_load_file($cache);
$expireNext = ($xml->track->callmeback / 1000);
if($expireNext < 10) $expireNext = 60;
@file_put_contents($cacheCall, $expireNext."
".time());
}
echo file_get_contents($cache);
}
?>
Paginas: http://timbox.s2.one2xs.com/call_api.php
http://timbox.s2.one2xs.com/cache_api.txt
http://timbox.s2.one2xs.com/cache_callapi.txt
Nadat ik voor een webradio het aantal luisteraars via een cache.txt weergeef moest ik dit van de "radio-provider" ook doen voor het huidige nummer.. Alleen wanneer ik alles invoer komt er in de cache file voor het huidige nummer de one2xs host pagina te staan.. Ik voeg 3 linkjes bij zodat jullie kunnen zien wat het geval is! Ik zal hieronder ook het call_api.php script bijvoegen! Iemand enig idee hoe ik dit kan fixen? Beloning 0.1 voor de goede oplossing.
Bij de luisteraars API werkt alles prima en wordt er goed gecached! De cache files zijn allemaal 777.
Codeblok (voorbeeld.php):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Votre RadioUID
$radiouid = "0be958e7-3925-4cba-98d0-d8517550e9bb";
// Votre APIKey
$apikey = "////geheim////";
// Récupération des pochettes
$cover = "no"; // "yes" ou "no"
/* --------------------------------- */
/* #### ! NE PAS MODIFIER ! #### */
/* --------------------------------- */
// Fichier de cache local
$cache = ./cache_api.txt;
$cacheCall = ./cache_callapi.txt;
$date = "-1";
// Test des droits daccès
if(substr(decoct(@fileperms($cacheCall)),3, 3) != "777" && substr(decoct(@fileperms($cacheCall)),3, 3) != "644" && !@chmod($cacheCall, 0777)){
echo Erreur ! Vous devez autoriser en écriture le fichier cache_callapi.txt;
exit;
}
if(substr(decoct(@fileperms($cache)),3, 3) != "777" && substr(decoct(@fileperms($cache)),3, 3) != "644" && !@chmod($cache, 0777)){
echo Erreur ! Vous devez autoriser en écriture le fichier cache_api.txt;
exit;
}
if($lines = file($cacheCall)){$date = (isset($lines[1]) ? $lines[1] : -1); $time = $lines[0]; $expire = time() - $time;}
else{$expire = time() - 1;}
if(@file_exists($cache) && $date > $expire && file_get_contents($cache) != ""){ echo file_get_contents($cache);}
else{
@file_put_contents($cacheCall, "200"."
".time());
$context = stream_context_create(array(http => array(timeout => 30)));
touch($cache);
$xml = @file_get_contents(http://api.radionomy.com/currentsong.cfm?radiouid=.$radiouid.&callmeback=yes&type=xml.(!empty($apikey) ? &apikey=.$apikey : )..(!empty($cover) ? &cover=.$cover : ).,0, $context);
if(!$xml)
$xml = @simplexml_load_file($cache);
else{
@file_put_contents($cache, $xml);
$xml = @simplexml_load_file($cache);
$expireNext = ($xml->track->callmeback / 1000);
if($expireNext < 10) $expireNext = 60;
@file_put_contents($cacheCall, $expireNext."
".time());
}
echo file_get_contents($cache);
}
?>
Paginas: http://timbox.s2.one2xs.com/call_api.php
http://timbox.s2.one2xs.com/cache_api.txt
http://timbox.s2.one2xs.com/cache_callapi.txt
