PHP执行采集任务,结果死机,但是每次执行一条却很快
【求助】PHP执行采集任务,结果死机,但是每次执行一条却很快。
PHP执行采集任务,程序写的步骤是
1.先从数据库中提取出url,
2.php远程获取URL标题title,通过http下载远程网址。
3.下载完之后下载另外一个网站B的数据,http。
4.下载完之后再次下载另外一个站C的数据,http。
5.每条记录总共下载远程四个网站A、B、C、D的数据后更新数据表的对应记录,然后循环下一条记录。
结果的现象是:
如果刷新一次页面一次10条都一直在加载,但是却始终都没有完成一条(三个小时候过去了,一条都没有完成)。
但是如果每次只操作一条,却很快的就完成了。一直难以明白,代码都没有改过。
------解决方案--------------------
是否是php超时了或者内存满了?
是否打开error.log查看下错误日志呢?
写这种采集程序,最重要的是判断程序运行错误的时候怎么处理。
------解决方案--------------------
多数都是代码问题...没代码 没真相
------解决方案--------------------
在每一个都写log入文件,看到哪一步停止了。
------解决方案--------------------
正解
------解决方案--------------------
你这个
一条也完不成的一次10条的代码
和
一条很快完成的一次一条的代码
到底有何不同之处?
------解决方案--------------------
哪里的服务器?先别解析一下DNS。
------解决方案--------------------
我是说siteA,也是本地的?先别采集。直接运行siteA的相应脚本,需要多少时间?
------解决方案--------------------
你没有给出具体的代码,不能给出具体的建议
不过就是给出了代码,也不一定有心情去看和测试
对此类应用提点我哥个人意见:
1、通常页面中都有返回到首页,返回到栏目之类的连接。
应注意排除,否则极易造成死循环
2、页面采集程序应是单一的
即运行一次,采集一个页面
3、采集控制程序用于调度页面采集程序
可用 fsockopen 打开 页面采集程序 后即可返回,目标页url只作为参数传递给页面采集程序
这样可就模拟了一个多进程系统
4、具体是实现时以数据库为中介,所有从页面中析出的url都入库(当然要排重)
采集控制程序读取数据库,以决定是否继续采集和每次采集的规模
------解决方案--------------------
换个类试试,不要用dedecms集成的。
网上找一下类似功能的function或者CLASS。
------解决方案--------------------
内牛满面....师兄你成仙了啊~~
自己写个采集的curl 封装一下 有多难哪...采集其实麻烦就麻烦在各种正则上的分析校对.
------解决方案--------------------
就是,二次开发没那么难。你到底要怎么样的功能?把URL和要求贴出来,帮你写一个function。
------解决方案--------------------
网络问题是影响采集速度的最主要原因。
你先ping一下,看看响应时间是多少。
别用dedecms的那个类,自己用curl写个,很简单的。
给每个请求设置timeout。别拿自己的pc机跑,找一台配置高的服务器去跑,开多个进程,把你的任务分类,这样可以提高好几倍的效率。
------解决方案--------------------
给出这些域名,是不是有头部跳转,或者去掉www看看。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

In this chapter, we are going to learn the following topics related to routing ?

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Validator can be created by adding the following two lines in the controller.
