Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 文件获取内容加速_Html_Timeout_File Get Contents - Fatal编程技术网

Html 文件获取内容加速

Html 文件获取内容加速,html,timeout,file-get-contents,Html,Timeout,File Get Contents,我正在创建一个rss提要发现服务,方法是抓取一个页面URL并在页面标题中找到标记。问题是一些url需要很长时间才能提供页面源代码,因此我的代码经常会停留在file\u get\u contents($url) 有没有一种方法可以通过预定义的超时来实现这一点,例如,如果10秒过去了,仍然没有提供任何内容,那么只需删除该URL并移动到下一个URL 我曾考虑使用maxLen参数仅获取部分源代码(。),但我不确定在接收到的字节达到后是否真的会停止,并且仍然需要完整的页面加载。另一个问题是,我不知道在这里

我正在创建一个rss提要发现服务,方法是抓取一个页面URL并在页面标题中找到
标记。问题是一些url需要很长时间才能提供页面源代码,因此我的代码经常会停留在
file\u get\u contents($url)

有没有一种方法可以通过预定义的超时来实现这一点,例如,如果10秒过去了,仍然没有提供任何内容,那么只需删除该URL并移动到下一个URL


我曾考虑使用
maxLen
参数仅获取部分源代码(
),但我不确定在接收到的字节达到后是否真的会停止,并且仍然需要完整的页面加载。另一个问题是,我不知道在这里设置什么值,因为每个页面的
标题中都有不同的内容,所以大小不同。

我刚刚读过这方面的内容,所以这只是目前的理论。。但是

这是函数定义,请注意资源上下文部分:

string file_get_contents ( string $filename [, bool $use_include_path = false [, **resource $context** [, int $offset = -1 [, int $maxlen ]]]] )
如果指定
stream\u context\u create()
函数的结果,并在其选项数组中传递超时值,那么它可能会工作

$context = stream_context_create($opts);
或者您可以创建流并直接设置其超时:

http://www.php.net/manual/en/function.stream-set-timeout.php

希望你能在这方面取得一些成功。

我刚刚读到这方面的文章,所以这只是目前的理论。。但是

这是函数定义,请注意资源上下文部分:

string file_get_contents ( string $filename [, bool $use_include_path = false [, **resource $context** [, int $offset = -1 [, int $maxlen ]]]] )
如果指定
stream\u context\u create()
函数的结果,并在其选项数组中传递超时值,那么它可能会工作

$context = stream_context_create($opts);
或者您可以创建流并直接设置其超时:

http://www.php.net/manual/en/function.stream-set-timeout.php

希望您能在这方面取得一些成功。

使用“上下文”参数。您可以使用“stream\u context\u create”函数创建流上下文,并在http上下文中指定所需的超时

$context = stream_context_create(array(
    'http' => array(
        'timeout' => YOUR_TIMEOUT,
    )
));
$content = file_get_contents(SOME_FILE, false, $context);
更多信息:

使用“上下文”参数。您可以使用“stream\u context\u create”函数创建流上下文,并在http上下文中指定所需的超时

$context = stream_context_create(array(
    'http' => array(
        'timeout' => YOUR_TIMEOUT,
    )
));
$content = file_get_contents(SOME_FILE, false, $context);
更多信息: 及