技术圈开发者交流群:

PHP7版的Des加解密,支持ECB,CBC等模式,兼容java、C#

最近对接一大堆接口,找了各种des加解密,很多都是php7以下的,要知道mcrypt_decrypt此类的方法再php7以上已经过时或废除了

Warning
This function has been DEPRECATED as of PHP 7.1.0 and REMOVED as of PHP 7.2.0. Relying on this function is highly discouraged.

搞了好久,好不容易看到了这个 https://blog.csdn.net/qq43599939/article/details/80226482 ,终于将C#、Java的代码转换成了php7的代码:

PHP 2018年08月24日 25637

使用GoLang语言爬虫,goquery+MongoDB爬取搜狗微信热点文章

goquery是一个使用go语言写成的HTML解析库,可以让你像jQuery那样的方式来操作DOM文档,使用起来非常的简便。

闲话少说,直接上代码:

package main

import (
    "gopkg.in/mgo.v2"
    "github.com/PuerkitoBio/goquery"
    "log"
    "gopkg.in/mgo.v2/bson"
)

type Article struct {
    Title      string
    Decription string
    Image      string
    Author     string
    Time       string
}

func main() {
    getArticle()
}

func getArticle() {

    //连接MongoDB数据库
    session, err := mgo.Dial("")
    if err != nil {
        panic(err)
    }
    defer session.Close()

    session.SetMode(mgo.Monotonic, true)
    c := session.DB("test").C("article")

    //使用goquery开始抓取
    doc, err := goquery.NewDocument("http://weixin.sogou.com/")
    if err != nil {
        log.Fatal(err)
    }

    //编辑文章节点
    doc.Find(".news-list li").Each(func(i int, contentSelection *goquery.Selection) {

        //文章标题
        title := contentSelection.Find(".txt-box h3 a").Text()
        decription := contentSelection.Find(".txt-box .txt-info").Text()
        image, _ := contentSelection.Find(".img-box img").Attr("src")
        author := contentSelection.Find(".txt-box .account").Text()
        time, _ := contentSelection.Find(".txt-box .s-p").Attr("t")

        result := Article{}

        //是否已经保存过该文章
        err = c.Find(bson.M{"title": title}).One(&result)

        if err != nil {
            log.Println("第", i+1, "篇文章:", title)
            //保存至数据库
            err = c.Insert(&Article{title, decription, image, author, time})
            if err != nil {
                panic(err)
            }
        }
        log.Println(result)
    })
}

MongoDB查看爬取到的文章:

GoLang 2018年08月21日 49235

Thinkphp5中配置XHProf性能分析工具

ThinkPHP中的行为是一个比较抽象的概念,你可以把行为想象成在应用执行过程中的一个动作。

不熟悉的xhprof的,请参考前一篇文章:http://www.tech1024.com/original/2990.html

如果你还不了解thinkphp的钩子行为,可以参考手册:https://www.kancloud.cn/manual/thinkphp5_1/354129

首先,我们在application/tags.php文件中,定义性能分析的行为,分别绑定在app_initapp_initApp初始化标和应用结束的钩子上:

PHP 2018年08月12日 65997

XHProf,PHP性能分析利器,快速定位代码瓶颈

很多项目,还没到考虑性能的时候就夭折了,而你项目是否到了要考虑性能优化的时候了?

经常会有人问,我的cpu正常,内存正常,数据库正常,可网站打开为什么就是?为什么就是

PHP 2018年08月01日 55030

PHP设计模式——简单工厂模式(Simple Factory)

工厂主要有三种模式:抽象工厂、简单工厂、工厂方法,本文所说的是简单工厂模式,其他两种模式也是大同小异。

项目中,在不确定有多少种处理操作时,可以用简单工厂模式。

比如:

数据库的连接,可能是mysql,也可能是oracle

PHP 2018年05月09日 65248

PHP设计模式——单例模式(Singleton)

简单说来,单例模式的作用就是保证在整个应用程序的生命周期中,任何一个时刻,单例类的实例都只存在一个,同时这个类还必须提供一个访问该类的全局访问点。

数据库连接器(mysql|Oracle|sqlServer);

缓存/日志(file|redis|memcached);

PHP 2018年05月09日 844

PHP实现类的自动加载,构建一个面向对象(OOP)的应用

在编写面向对象(OOP) 程序时,通常是一个类新建一个 PHP 文件。 然而,在调用其他类的时候都需要去包含(include或require)这个类所在的php文件。

有没更简单的方法呢,答案当然是 有!!!

使用 spl_autoload_register() 函数注册任意数量的自动加载器。

PHP 2018年05月07日 55068

Apache2.4和PHP7整合,以模块模式配置

前面的文章分别介绍了Apache和php的安装,这里介绍Apache和php的整合,这里以模块模式运行php

确保安装php的时候指明了--with-apxs2参数

编辑Apache配置文件:

Linux 2018年04月12日 57918

Centos环境下编译安装PHP7.2

在安装之前,请参考之前的几篇文章

这里以PHP7.2为例

安装必要的依赖库,如果已经安装则可跳过

yum -y install gcc gcc-c++ net-tools wget file libtool libtool-libs autoconf libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel unzip tar bzip2 bzip2-devel libevent libevent-devel curl curl-devel libcurl libcurl-devel openssl openssl-devel libicu-devel libxslt libxslt-devel
Linux 2020年02月17日 58529
鄂ICP备19028750号-1 @copyright 2024 tech1024.com