V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
fghfjujiber
V2EX  ›  问与答

在写 PHP 爬虫,因为 file_get_contents 卡死了,怎么办?

  •  
  •   fghfjujiber · 2015-07-07 16:10:57 +08:00 · 3219 次点击
    这是一个创建于 3218 天前的主题,其中的信息可能已经有所发展或是发生改变。

    因为部分页面是ajax动态加载的,所以要用file_get_contents获取json数据。

    8 条回复    2015-07-07 18:12:16 +08:00
    dalaomj
        1
    dalaomj  
       2015-07-07 16:14:01 +08:00
    用fsockopen或者curl,可以自定义的元素更多。file_get_contents连UA都是在php.ini里定义的。
    b821025551b
        2
    b821025551b  
       2015-07-07 16:14:47 +08:00
    超时,or换curl
    hjxx
        3
    hjxx  
       2015-07-07 16:15:27 +08:00
    fghfjujiber
        4
    fghfjujiber  
    OP
       2015-07-07 16:16:01 +08:00
    好的我试一试
    tabris17
        5
    tabris17  
       2015-07-07 16:17:18 +08:00
    通过 stream_context参数可以设置超时
    yeyeye
        6
    yeyeye  
       2015-07-07 17:57:42 +08:00
    @dalaomj file_get_contents可以在用 到时候设置UA等其他请求参数
    lincanbin
        7
    lincanbin  
       2015-07-07 17:57:57 +08:00
    用curl。
    lshero
        8
    lshero  
       2015-07-07 18:12:16 +08:00
    @dalaomj stream_context_create挺有用的file_get_contents时可以配合使用
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2334 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:11 · PVG 00:11 · LAX 09:11 · JFK 12:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.