0

I`m still not really comfortable with PHP and furthermore completly new to Json. What i want to do is check out if a specific Twitch.tv Livestream is online or not, also i want to get the viewers. Twitch.tv has its own API ( https://github.com/justintv/Twitch-API/wiki/API ) with which, this should be possible. Here is my first approach:

// Twitch Streams
else if($typ == 't') {
    $api    = file_get_contents("https://api.twitch.tv/kraken/streams/".$stream_id);
    $json   = json_decode($api);
    if($json->stream != null) {
        return true;    
    }
    else {
        return false;   
    }
}

The problem is that file_get_contents seem to not understand https, it claimes that the wrapper is not installed. The thing is that normal http requests are not supported by the API, so i guess i have to use another function. Can somebody suggest me a different (not so hard to use) function. I have read about curl and fsocket but they seem a bit difficult to use for me.

Jakob Abfalter
  • 4,980
  • 17
  • 54
  • 94

2 Answers2

1

PHP Curl should be able to help with this.

The link below illustrates how to get the http code: http://php.net/manual/en/function.curl-getinfo.php

Mark1inLA
  • 196
  • 1
  • 7
  • so i tried to use Curl now... First the following error `Fatal error: Call to undefined function curl_init()` Googling a bit i found out, that with my version i have to uncommend the curl extension in the php.ini which i did, than the following error: `PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.3.13/ext/php_curl.dll' - The application has failed to start because its side-by-side configuration is incorrect. ` I found out this is a problem with wamp and found a fix on http://www.anindya.com/ which made my php not working anymore. SO FU CURL!!! – Jakob Abfalter Dec 29 '12 at 12:30
  • LOL, it's not cURL's fault your environment isn't configured to use it. I'm a fan of Zend Server because it makes managing the environment much easier. – Mark1inLA Jan 17 '13 at 21:40
1

https:// might not be enabled. This post might help you find out why: How to get file_get_contents() to work with HTTPS?. There should be no reason why you have to use cURL, but cURL is usually more flexible so i would advice you to use that instead if you are able to comprehend how it is working.

Community
  • 1
  • 1
Andreas Hagen
  • 2,335
  • 2
  • 19
  • 34
  • Neither one of them does work for me. I enabled the php_openssl.dll and wrote allow_url_include = On in the php.ini. Still the same error. Curl also doesnt work for me: `PHP Startup: Unable to load dynamic library 'c:/wamp/bin/php/php5.3.13/ext/php_curl.dll' - The application has failed to start because its side-by-side configuration is incorrect.` Is there another (not so buggy) method to do this? – Jakob Abfalter Dec 29 '12 at 12:33
  • Indeed it is. Get rid of WAMP; It's standard configuration is horrible, which might cause your errors. If you install Apache/PHP manually it will probably be a lot easier to work with. Also the PHP installer can configure cURL and other extensions for you so that you don't mess it up yourself. =) Side-note: What causes this exact error while loading cURL is probably a misplaced .dll or wrong read/execute permissions in the filesystem. – Andreas Hagen Dec 29 '12 at 12:48
  • Thanx for the advice i already got the ssl working, i had to enable the extension in the php.ini in apache folder also to get it running. I actually liked Wamp so far, imo its at least a lot better than Xamp. – Jakob Abfalter Dec 29 '12 at 12:54