php ://input 消息头 消息体,php curl_init curl 消息头和消息体

给定一个 远程图片地址(http地址) 然后用curl 请求 通过检查返回的 消息头 判断远程图片是否存在

但是这里有个严重的效率问题就是消息体

消息体把图片也给返回了 有设置可以 只产生消息体 让消息体为空或者或不产生消息体吗

//检查远程文件

function checkRemoteFile($file_name, $path) {

$path = $path . "/" . $file_name;

$ch = curl_init();

$timeout = 30; //在尝试连接时等待的秒数。设置为0,则无限等待。

curl_setopt($ch, CURLOPT_URL, $path);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$contents = curl_exec($ch);

//echo $contents;

if (preg_match("/404/", $contents)) {

echo '0';

return false;

} elseif(preg_match("/200/", $contents)) {

echo $contents;

return true;

}

}

回复内容:

给定一个 远程图片地址(http地址) 然后用curl 请求 通过检查返回的 消息头 判断远程图片是否存在

但是这里有个严重的效率问题就是消息体

消息体把图片也给返回了 有设置可以 只产生消息体 让消息体为空或者或不产生消息体吗

//检查远程文件

function checkRemoteFile($file_name, $path) {

$path = $path . "/" . $file_name;

$ch = curl_init();

$timeout = 30; //在尝试连接时等待的秒数。设置为0,则无限等待。

curl_setopt($ch, CURLOPT_URL, $path);

curl_setopt($ch, CURLOPT_HEADER, 1);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

$contents = curl_exec($ch);

//echo $contents;

if (preg_match("/404/", $contents)) {

echo '0';

return false;

} elseif(preg_match("/200/", $contents)) {

echo $contents;

return true;

}

}

不用curl不就行了,fopen好像也可以打开远程文件吧。

$hd = fopen($remoteUrl, 'r');

if ($hd === false) die('404')

else fclose($hd);

哦,看到你的评论了,用 curl_setopt($ch, CURLOPT_NOBODY, true); 看看

curl不可以吗?你试试这个呢!

public function checkRemoteHttpFileExists($url) {

$curl = curl_init($url);

// 不取回数据

curl_setopt($curl, CURLOPT_NOBODY, true);

curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'GET');

// @curl_setopt($curl, CUROPT_RETURNTRANSFER,1);

// 发送请求

$result = @curl_exec($curl);

$found = false;

// 如果请求没有发送失败

if ($result !== false) {

// 再检查http响应码是否为200

$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);

if ($statusCode == 200) {

$found = true;

}

}

curl_close($curl);

return $found;

}

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现OpenWrt系统开机自动播放指定的音频流,您可以使用Mpd软件和Crontab定时任务。 以下是具步骤: 1. 安装Mpd软件 在终端中输入以下命令安装Mpd软件: ``` opkg update opkg install mpd ``` 安装完成后,Mpd会自动启动。 2. 配置Mpd播放器 在终端中输入以下命令打开Mpd配置文件: ``` vi /etc/mpd.conf ``` 在配置文件中,您需要添加以下内容: ``` audio_output { type "alsa" name "Output device" } audio_output { type "httpd" name "MPD HTTP Stream" encoder "vorbis" # or "lame" or "flac" port "8000" quality "5.0" format "44100:16:2" } audio_input { type "httpd" name "My HTTP Stream" encoder "vorbis" # or "lame" or "flac" format "44100:16:2" mixer_type "software" mixer_device "default" mixer_control "PCM" cache_buffer_size "32768" input { plugin "curl" enabled "yes" proxy "" proxy_user "" proxy_password "" user_agent "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0" buffer_time "1500000" reconnect_interval_max "30" max_connections "1" } } } ``` 其中,第一个audio_output配置用于输出音频到OpenWrt系统的声卡设备,第二个audio_output配置用于将音频流以HTTP协议的方式输出,方便在其他设备上播放。 最后一个audio_input配置用于指定要播放的音频文件的URL。 保存并退出配置文件。 3. 测试Mpd播放器 在终端中输入以下命令启动Mpd: ``` /etc/init.d/mpd start ``` Mpd启动后,在其他设备上访问http://OpenWrt系统IP地址:8000即可播放音频流。 4. 设置Crontab定时任务 在终端中输入以下命令打开Crontab配置文件: ``` vi /etc/crontab ``` 在配置文件中,添加以下内容: ``` @reboot root /usr/bin/mpc play http://lhttp.qingting.fm/live/4915/64k.mp3 ``` 其中,@reboot表示定时任务在系统重启时执行,/usr/bin/mpc play http://lhttp.qingting.fm/live/4915/64k.mp3表示执行Mpc播放器播放指定的音频流。 保存并退出配置文件。 现在,您已经成功设置OpenWrt系统开机自动播放指定的音频流了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值