1

I need to get Icecast metadata auto update by PHP let say every 15 min which will be done by cPanel cronjob.

i had the below code but it does't work(it works if I use header location to redirect however cronjob won't be able to do that)

<?PHP
$url="http://tgftp.nws.noaa.gov/data/observations/metar/stations/KJFK.TXT";
$info=file_get_contents($url);
$url_info = "http://username:password@icecast:8000/admin/metadata?mount=/mymount&mode=updinfo&song=" . urlencode($info);

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url_info);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);

?>
Ng Wilson
  • 21
  • 5

1 Answers1

1

Try checking for errors after you execute the call using curl_error:

<?php
$url="http://tgftp.nws.noaa.gov/data/observations/metar/stations/KJFK.TXT";
$info=file_get_contents($url);
$url_info = "http://username:password@icecast:8000/admin/metadata?mount=/mymount&mode=updinfo&song=" . urlencode($info);

// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url_info);
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser, check for errors
if (curl_exec($ch) === FALSE)
{
  print 'Curl-Error occurred: ' . curl_error($ch).', error code: '.curl_errno($ch);
}

// close cURL resource, and free up system resources
curl_close($ch);
SaschaM78
  • 4,376
  • 4
  • 33
  • 42
  • Thanks, it seems is my php server unable to connect to the ice cast server.. issue solved – Ng Wilson Feb 20 '18 at 13:57
  • In case you are using a proxy, check [this question](https://stackoverflow.com/questions/5211887/how-to-use-curl-via-a-proxy). Beside that, [`curl_getinfo()`](http://php.net/manual/en/function.curl-getinfo.php) may also help you find the underlying problem. And thanks for accepting! – SaschaM78 Feb 20 '18 at 14:46