抓取时无法加载太大的html文件 [英] can't load too big html file when grab

查看:135
本文介绍了抓取时无法加载太大的html文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题.我试图抓住HTML文件.但是此文件的大小为350 mb.当我尝试使用file_get_contents加载它并使用DOM时,它不显示任何输出.只是一个白色的背景.当我尝试使用小文件时,它可以工作.我为什么要这样做.

here's my problem. i have tried to grab html file. but this file have 350 mb size. and when i tried to load it with file_get_contents and using DOM it not showing any output. just a white background. when i tried with small file, it's works. why should i do.

<?php

// error_reporting(E_ALL);
// ini_set('display_errors', 1);
ini_set('max_execution_time',5000);

$source=file_get_contents("C://xampp/htdocs/Champion/machine-
logs/LogPrinting03/RIPLOG.HTML");
$dom = new DOMDocument();

$dom->loadHTML($source);

echo $source;

?>

推荐答案

尝试使用以下代码在您的应用程序的PHP.ini或本地内存中增加内存限制:

Try to increase the memory limit in your PHP.ini or locally for your app using the following code :

// I'm setting the memory limit to 1024M, but it should work with less memory
ini_set('memory_limit','1024M');
// Enable error reporting - TO BE REMOVED BEFORE YOU GO TO PRODUCTION
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
ini_set('max_execution_time',5000);

$source=file_get_contents("C://xampp/htdocs/Champion/machine-
logs/LogPrinting03/RIPLOG.HTML");
$dom = new DOMDocument();

$dom->loadHTML($source);

echo $source;

这篇关于抓取时无法加载太大的html文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆