php 更新 Icecast 元数据

Icecast metadata update by php

我需要通过 PHP 让 Icecast 元数据自动更新,假设每 15 分钟将由 cPanel cronjob 完成。

我有下面的代码但它不起作用(如果我使用 header 位置重定向它会起作用但是 cronjob 将无法做到这一点)

<?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);

?>

使用 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);