fghfjujiber
V2EX  ›  问与答

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

  •  
  •   fghfjujiber · Jul 7, 2015 · 4285 views
    This topic created in 4148 days ago, the information mentioned may be changed or developed.

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

    8 replies  •  2015-07-07 18:12:16 +08:00
    dalaomj
    dalaomj
    Jul 7, 2015
    1
    用fsockopen或者curl,可以自定义的元素更多。file_get_contents连UA都是在php.ini里定义的。
    b821025551b
    b821025551b
    Jul 7, 2015
    2
    超时,or换curl
    fghfjujiber
    fghfjujiber
    OP
    Jul 7, 2015
    4
    好的我试一试
    tabris17
    tabris17
    Jul 7, 2015
    5
    通过 stream_context参数可以设置超时
    yeyeye
    yeyeye
    Jul 7, 2015
    6
    @dalaomj file_get_contents可以在用 到时候设置UA等其他请求参数
    lincanbin
    lincanbin
    Jul 7, 2015
    7
    用curl。
    lshero
    lshero
    Jul 7, 2015
    8
    @dalaomj stream_context_create挺有用的file_get_contents时可以配合使用
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1716 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 15:56 · PVG 23:56 · LAX 07:56 · JFK 10:56
    ♥ Do have faith in what you're doing.