作者: admin

  • PHP利用CURL实现 http post 和 get

    PHP利用CURL实现HTTP GET和HTTP POST,用于HTTP请求,具体代码如下:

    <?php
    //初始化
    $curl = curl_init();
    //设置抓取的url
    curl_setopt($curl, CURLOPT_URL, 'http://www.baidu.com');
    //设置头文件的信息作为数据流输出,如果不想打印出http头,可以把这行去掉
    curl_setopt($curl, CURLOPT_HEADER, 1);
    //设置获取的信息以文件流的形式返回,而不是直接输出。
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    //执行命令
    $data = curl_exec($curl);
    //关闭URL请求
    curl_close($curl);
    //显示获得的数据
    print_r($data);

    HTTP POST:

    <?php
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL,$notify_url);
    curl_setopt($ch, CURLOPT_POST, 1);
    
    
    //curl_setopt($ch, CURLOPT_POSTFIELDS, "postvar1=value1&postvar2=value2&postvar3=value3");
    
    $notifyData = [];
    
    // In real life you should use something like:
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($notifyData));
    
    // Receive server response ...
    // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    curl_exec($ch);
    
    curl_close($ch);
    
    // echo $server_output;
    
  • 查看Debian定时任务执行日志

    执行下面的命令:

    grep CRON /var/log/syslog | tail -10
  • 天翼云和华为云初体验

    今天博客园送的华为云服务器开通了,晚上花了一个小时的时间简单体验了一下,感觉还不错。

    我安装的是 Debian 系统,华为云直接有最新的12版本,只要apt update && apt upgrade一下就可以一键升级到的最新的12.7版本了,这点比天翼云方便,天翼云只有 Debian11。

    华为云服务器 Debian 镜像已经设置好了华为云的源,使用起来非常方便,不用自己再进行调整。而天翼云就没有,要自己动手修改。

    另外,天翼云的 Debian 镜像配置有点小问题,/etc/hosts 里面没有和 hostname 关联的记录,导致使用起来有点小问题,具体什么问题当时忘记记录了,反正是有。还有就是系统的区域配置有问题,只有 en_US,没有 en_DK,导致对日期格式的支持有些问题,apt 安装包时有警告。还有一些小问题记不太清了。反观华为云就用的很顺畅,命令敲下去一气呵成、酣畅淋漓。

    还有,天翼云比较严格,常用的端口都是不能用的,直接用 IP 都不行。要用的话只能迁移备案,但众所周知,这是个麻烦事,这台37块钱的服务器大概率要吃灰。

    总体来说,华为云用的比较安逸,体验比天翼云要好。

    注:本文始发于我的博客园博客 https://www.cnblogs.com/art ,之后重新发于本站。

  • phpMyAdmin 初次安装配置

    将 config.sample.inc.php 复制一份,把复制后的文件改名为 config.inc.php,把$cfg['blowfish_secret']修改为

    $cfg['blowfish_secret'] = '419f9149e486203888b17fee459c2912'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
  • Debian12 安装 PHP8.3

    当前 Debian12 官方源中带的 PHP 版本是8.2,而 PHP8.2 的 Active Support 到今年年底(31 Dec 2024),所以直接装8.3吧,可以用的时间长一点。

    首先安装sury源

    #!/bin/sh
    # To add this repository please do:
    if [ "$(whoami)" != "root" ]; then
        SUDO=sudo
    fi
    ${SUDO} apt-get update
    ${SUDO} apt-get -y install lsb-release ca-certificates curl
    ${SUDO} curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
    ${SUDO} dpkg -i /tmp/debsuryorg-archive-keyring.deb
    ${SUDO} sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
    ${SUDO} apt-get update

    注意,如果安装sury源时报错:

    The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY B188E2B695BD4743

    意思是系统缺少sury源的公钥。只要把公钥下载到系统就可以了,执行以下命令添加公钥:
    wget -qO /etc/apt/trusted.gpg.d/sury-php.gpg https://packages.sury.org/php/apt.gpg
    公钥添加完成后,执行apt update刷新包列表即可。

    然后执行以下命令安装PHP8.3:

    apt install -y php8.3-fpm php8.3-mysql php8.3-mbstring php8.3-curl php8.3-xml php8.3-imagick php8.3-zip php8.3-gd php8.3-intl php8.3-bcmath

    如果需要支持 Laravel 框架,那么最后一个 bcmath 扩展是必须的。

  • Debian11 升级 Debian12

    今天通过博客园首页链接购买了37块钱的天翼云,发现 Debian 最新版本只到11,那么就来升级一下吧。

    1、更新当前系统apt updateapt full-upgrade,更新完后发现有一个包没有被升级0 upgraded, 0 newly installed, 0 to remove and 1 not upgraded.,执行apt list --upgradable -a看了一下,输出如下:

    root@vm:~# apt list --upgradable -a
    Listing... Done
    base-files/oldstable 11.1+deb11u11 amd64 [upgradable from: 11.1+deb11u1]
    base-files/now 11.1+deb11u1 amd64 [installed,upgradable to: 11.1+deb11u11]

    应该是一个涉及核心系统的包,手动升级一下吧: apt-get install base-files

    2、更新完成后,更换 Debian12 的源,首先备份当前源 mv /etc/apt/sources.list /etc/apt/sources.list.old,然后写入 Debian12 的源,这里用的是清华的源:

    cat > /etc/apt/sources.list << EOF
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
    EOF

    3、继续更新系统apt updateapt full-upgrade,期间会有一些提示信息,根据需要选择。

    更新完后,查看系统版本cat /etc/debian_version, 我这里显示的是12.7,嗯,最新版本 Debian 已经更新好了。

    Debian 大版本升级还是一如既往的丝滑,从来没有让我失望过👍💖。

    注:本文始发于我的博客园 https://www.cnblogs.com/art ,之后重新发于本站。

  • Debian 更换国内清华源

    1、备份原文件 mv /etc/apt/sources.list /etc/apt/sources.list.old

    2、写入新源,以下是 Debian 11 的:

    cat > /etc/apt/sources.list << EOF
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye main contrib non-free
     
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-updates main contrib non-free
     
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bullseye-backports main contrib non-free
     
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security/ bullseye-security main contrib non-free
    EOF

    如果是 Debian 12:

    cat > /etc/apt/sources.list << EOF
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
    
    deb https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
    deb-src https://mirrors.tuna.tsinghua.edu.cn/debian-security bookworm-security main contrib non-free non-free-firmware
    EOF

    注:

    deb 指向的是编译好的二进制软件包。
    deb-src 指向的是软件的源代码包,可以使用apt source命令下载软件的源代码并自行编译。

    注:本文始发于我的博客园 https://www.cnblogs.com/art ,之后重新发于本站。

  • PHP 常用代码片断

    记录了一些PHP常用的代码片段,方便查阅使用。

    <?php
    // 判断请求类型
    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    }
    
    //php 判断是否为 ajax 请求
    if (isset($_SERVER["HTTP_X_REQUESTED_WITH"]) && strtolower($_SERVER["HTTP_X_REQUESTED_WITH"]) == "xmlhttprequest") {
        // ajax 请求的处理方式 
    } else {
        // 正常请求的处理方式 
    }
    
    // PHP设置页面编码:
    header("Content-type:text/html; charset=utf-8");
    
    header("Content-type:application/json;charset=utf-8");
    
    // PHP获取当前时间:
    date("Y-m-d H:i:s");
    
    // PHP获取页面执行时间:
    // 在脚本最后添加
    echo microtime(TRUE) - $_SERVER['REQUEST_TIME_FLOAT'];
    
    // PHP header跳转:
    header("Location: http://www.baidu.com/");
    
    // PHP清空所有session:
    session_destroy();
    
    // 获取昨天日期
    date("Y-m-d", strtotime("-1 day"));
    
    // 当前时间:
    date('Y年m月d日 H点i分s秒', time());

     

     

  • Debian 全局安装composer

    在 debian 上安装 compoer ,以便能够在任何地方随时执行compoer 命令,安装方法如下:

    php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" php composer-setup.php --install-dir=/usr/bin --filename=composer
    rm -rf composer-setup.php
    chmod +x /usr/bin/composer
    composer --version
  • 删除 composer  stand-with-ukraine

    最近发现在使用composer时,会输出一行stand-with-ukraine的文本内容,把政治掺杂到技术中,也是够烦人的,幸好有办法去掉,执行以下命令:

    composer remove ukeloop/stand-with-ukraine