我是靠谱客的博主 缓慢黑猫,这篇文章主要介绍failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found,现在分享给大家,希望可以做个参考。
PHP Warning 'yiibaseErrorException' with message 'file_get_contents(https://img12.360buyimg.com/n5/s1200x800_jfs/t1/69307/10/5911/292411/5d3e610cEce4e6f5a/b69fbf56874af00d.jpg): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
上面问题很多种处理方案;比如使用curl等可以参考其他使用产景
定时任务脚本中存在一个批量遍历去请求图片的接口;特别是脚本中,一定的要兼容好,比如try等
复制代码
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68/** * Created by XX * description: 批量同步支付宝商品文件 */ public function actionSyncAlipayGoodsFile() { set_time_limit(0); date_default_timezone_set("PRC"); $store_list = array_column(Store::find()->where(['is_delete' => 0, 'is_recycle' => 0])->select(['id'])->asArray()->all(), 'id'); if (empty($store_list)) { return; } //遍历商户 foreach ($store_list as $store_id) { $key = CacheKeyEnum::ALIPAY_GOODS_FILE.$store_id; $redis = Yii::$app->redis; $len = $redis->llen($key); if(!$len){ continue; } $successCount = $errorCount = 0; for ($i=1; $i<=$len; $i++) { $good = $redis->rpop($key); if($good){ $good = json_decode($good,true); if($good['cover_pic']){ //避免图片不存在导致脚本中断问题 if(!@fopen($good['cover_pic'], 'r' )){ continue; } $file_content = saveAlipayTempImage(file_get_contents($good['cover_pic'])); $config = MpConfig::get($store_id); //避免未知原因实例化失败导致其他商户受影响 try { $aop = $config->getClient(); } catch (InvalidArgumentException $ex) { continue; } try { $request = AlipayRequestFactory::create('alipay.merchant.item.file.upload', [ 'scene'=> 'SYNC_ORDER', 'file_content'=> '@'.$file_content ]); $response = $aop->execute($request); $data = $response->getData(); if(isset($data['material_id']) && $data['material_id']){ appmodelsGoods::updateAll(['material_id'=>$data['material_id'],'material_key'=>$data['material_key'],'material_status'=>1],['id'=>$good['id']]); $successCount+=1; Yii::$app->redis->incr(CacheKeyEnum::ALIPAY_GOODS_FILE_SUCCESS.$store_id); }else{ appmodelsGoods::updateAll(['material_reason'=>$data['sub_msg'],'material_status'=>2],['id'=>$good['id']]); $errorCount+=1; Yii::$app->redis->incr(CacheKeyEnum::ALIPAY_GOODS_FILE_FAIL.$store_id); } }catch (AlipayException $ex) { $errorCount+=1; Yii::$app->redis->incr(CacheKeyEnum::ALIPAY_GOODS_FILE_FAIL.$store_id); Yii::error(['data' => $ex->getMessage()], '支付宝订单中心:商品文件上传失败'); } } } } Yii::$app->redis->del(CacheKeyEnum::ALIPAY_GOODS_FILE.$store_id.'TotalCount'); } echo 'batch sync alipay goods file success'. "n"; }
最后
以上就是缓慢黑猫最近收集整理的关于failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found的全部内容,更多相关failed内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复