Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 还是关于PHP的二进制流问题

还是关于PHP的二进制流问题

Jun 23, 2016 pm 01:35 PM

之前发了一帖: http://bbs.csdn.net/topics/391024843
版主给了回答,也能够解析出来,但却发现出来的结果与真实结果完全不一样,比如服务器返回给我的是: ip: 107.145.107.140, port: 26773
但我解析出来却变成了: ip: 46.48.46.48, port: 63271
这样就差的远了, 我用PHP去获取nodes信息,然后将nodes信息自己解析输出一遍,顺便把未解析数据发送给pthon解析一遍,然后两边对比,发现结果却不一样

PHP(使用了swoole):

<?php$serv = new swoole_server('0.0.0.0', 6882, SWOOLE_PROCESS, SWOOLE_SOCK_UDP);$serv->set(array(    'worker_num' => WORKER_NUM,    'daemonize' => false,    'max_request' => MAX_REQUEST,    'dispatch_mode' => 2,    'debug_mode' => 1));$serv->on('Start', function($serv){    echo "DHT Server start...\n";    $nid = get_node_id();    $msg = array(        't' => entropy(2),        'y' => 'q',        'q' => 'find_node',        'a' => array(            'id' => $nid,            'target' => $nid        )    );    $serv->sendto(gethostbyname('router.bittorrent.com'), 6881, encode($msg));});$serv->on('Receive', function($serv, $fd, $from_id, $data){    echo "New receive from ip: ";    $msg = decode($data);    $fdinfo = $serv->connection_info($fd);    echo $fdinfo['remote_ip'] . "\n";    if($msg['y'] == 'r'){        if(array_key_exists('nodes', $msg['r']))            //$this->response_actions($msg, array($fdinfo['remote_ip'], $fdinfo['remote_port']));            $nodes = decode_nodes($msg['r']['nodes']);            foreach($nodes as $node){                echo "nid: " . $node->nid . ", ip: " . $node->ip . ", port: " . $node->port . "\n";            }            $serv->sendto('127.0.0.1', 6813, $data);    }});function entropy($length=20){        $s = '';        for($i=0;$i<$length;$i++)            $s .= chr(mt_rand(0, 255));        return $s;    }function get_node_id(){        return sha1(entropy());    }function get_neighbor($target, $nid){        return substr($target, 0, 10) . substr($nid, 0, -10);    }function encode($msg){        return Bencode::encode($msg);    }function decode($msg){        return Bencode::decode($msg);    }function decode_nodes($msg){        $n = array();        $length = strlen($msg);        // 由于每个node都为26位, 若总长度不等于26的倍数则直接返回        if(($length % 26) != 0)            return $n;        $i = 0;        while($i<$length){            //$s = substr($msg, $i, 26);            //$d = unpack('a20nid/Lip/Sport', $s);            //var_dump($d);            //$d = unpack('a20nid/lip/sport', $s);            //var_dump($d);            //$n[] = new Node($d['nid'], long2ip($d['ip']), $d['port']);            $nid = substr($msg, $i, 20);            var_dump($nid);            $ip = substr($msg, $i+20, 4);            var_dump($ip);            $ip = long2ip(unpack('L', $ip)[1]);            $port = substr($msg, $i+24, 2);            var_dump($port);            $port = unpack('s', $port)[1];            var_dump($port);            //$n[] = new Node($nid, $ip, $port);            $i += 26;        }        return $n;    }$serv->start();
Copy after login


python:
#!/usr/bin/env python#encoding: utf-8import socketfrom hashlib import sha1from random import randintfrom struct import unpackfrom socket import inet_ntoafrom threading import Timer, Threadfrom time import sleepfrom collections import dequefrom bencode import bencode, bdecodedef decode_nodes(nodes):    n = []    length = len(nodes)    if(length % 26) != 0:        return n    for i in range(0, length, 26):        nid = nodes[i:i+20]        ip = inet_ntoa(nodes[i+20:i+24])        ip2 = nodes[i+20:i+24]        print ip2        port = unpack("!H", nodes[i+24:i+26])[0]        port2 = nodes[i+24:i+26]        print port2        print "decode_nodes: nid: %s, ip: %s, port: %s\n" % (nid, ip, port)class DHTServer():    def __init__(self):        self.ufd = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)        self.ufd.bind(("0.0.0.0", 6813))    def process_find_node_response(self, msg, address):        nodes = decode_nodes(msg["r"]["nodes"])        for node in nodes:            (nid, ip, port) = node            print "find_node: nid: %s, ip: %s, port: %s\n" % (nid, ip, port)    def run(self):        while True:            try:                (data, address) = self.ufd.recvfrom(65536)                msg = bdecode(data)                self.on_message(msg, address)            except Exception:                pass    def on_message(self, msg, address):        try:            if msg["y"] == "r":                if msg["r"].has_key("nodes"):                    self.process_find_node_response(msg, address)        except KeyError:            passif __name__ == "__main__":    # max_node_qsize bigger, bandwith bigger, spped higher    dht = DHTServer()    dht.run()
Copy after login


回复讨论(解决方案)

你把执行 decode_nodes($msg) 时的 $msg 用
echo base64_encode($msg);
输出出来看看

这个不是base64编码,而是类似于:
未编码: {"t":"aa", "y":"r", "r":{"id":"0123456789abcdefghij", "nodes":"def456..."}}
编码后:d1:rd2:id20:0123456789abcdefghij5:nodes9:def456...e1:t2:aa1:y1:re
这样的格式

而其中的nodeid、ip、port就是其中的nodes里的

你把执行 decode_nodes($msg) 时的 $msg 用
echo base64_encode($msg);
输出出来看看



这里有份DHT协议说明: http://blog.csdn.net/xxxxxx91116/article/details/7970815

我又不做这个,没兴趣看协议文本

我给你的解码格式是小端序的,如果你的数据是大端序的,那么就查一下 pack 函数说明,换一下

如果你想让我帮你检查,那么就请按我说的去做

4楼版主说的对,检查大小端序的问题。
或者用tcpdump实际的二进制数据是什么样的。

现在已经能够正确获取IP地址,但是端口依然无解,也的确是使用大端序,但PHP只有这几种格式,每个都试过,就是不正确,郁闷了。。。

那有什么办法呢?让你贴出数据你又不肯,只能这样了

啊,没有不肯啊,是这样的:
比如服务器发了一段数据过来,ip是:188.19.238.146,端口是:6881,然后我截取端口位的2字节数据为:?
接着就是解码,将网络字节序转换为端口号:unpack("n", $port),但是转换出来却变成了57763,用unpack("s", $port)变成了-23583,用unpack("S", $port)变成了41953

让你把你收到的数据用 base64_encode 编码后给我,怎么就那么难呢?

让你把你收到的数据用 base64_encode 编码后给我,怎么就那么难呢?


抱歉,是这样的数据:
ZDE6cmQyOmlkMjA6daCpq0ZCdc6JP5An4ac4g4tlvPg1Om5vZGVzNDE2Oj4jyz4WVIOIxzAe2MXW4TWcH8dddZ6SRDktJ+7silGRA0YlQqlqucmPix2E6MZCvQ2ZY90lCzORZu5ZytoyWpBtKzh4PVNLMrz+Vo4exiqGYEUq3sV501VNWQ5XcqsXfXftr47cYrvZHsF4DCDFWnMcgC2Aq/DHVz00Wbxfm9qPqlsdaJ4um4dXnVtZ6BLCGgy42Pw3zVOnROrqVgpFb1J5g+BAxB2NOUMBBW7FQCyycNBojCpaDATl59Ekq4HpaHqD1gW057xisIRLgEp9f9VZvdr60s6C3CBNCX/OvoTfeJyY40k3SdswZ1lTimGVQRb7T7/VTO1rgXkZFTpuvAYbPCJaWUpbXcILoZh8A8H/qzKyirIM0v8lycJgFFdeiZR7bq+aPmxHVL1Scc6M3YMH17kiA8lK3l06cqN65EvX3/CuWJ4uw+fDhqSjVCkrwlpdQYO8k8mjkZhdVAaHCBUDxw9ESlvAXxuYGuFHYq2GV1BOhSYgmPJSaOzkghl0kq9lCiQvWUhr/ewsm/X/90CEXsTS45jet3HqWuZ2KcjVZTE6dDI6e8cxOnkxOnJl
Copy after login

python 中有

    n = []    length = len(nodes)    if(length % 26) != 0:        return n
Copy after login
Copy after login
而你给的数据(解码后)长度是 474
模 26 为 6
请确认你给的数据是正确的

python 中有

    n = []    length = len(nodes)    if(length % 26) != 0:        return n
Copy after login
Copy after login
而你给的数据(解码后)长度是 474
模 26 为 6
请确认你给的数据是正确的



哦,抱歉,是这样的,刚才给出的是获取到的原始数据,而之后那里 % 26那个是通过bencode解码后的nodes数据,不好意思,忘了把这份数据也弄出来。。。

这份是原始数据,包含了获取到的所有,比如:y = r 之类的
ZDE6cmQyOmlkMjA6O+Bji1UaqD0DtxQvYyoA6qxsWGQ1Om5vZGVzNDE2Oj/SyPVGoEWNKA31UnEp7simR5o0TuvCi3ZXP9LI9UagRY0oDfVScSnuyKZHmjRO68KLdlc/0sj1RqBFjSgN9VJxKe7IpkeaNE7rwot2Vz/8I+41PITGHXJVPESiGTTO7b2UsbfqyB+QP/wj7jU8hMYdclU8RKIZNM7tvZSxt+rIH5A//CPuNTyExh1yVTxEohk0zu29lLG36sgfkD//TOin7ijhPGnlvhNEku1IO1B2ZcxGPhrhP/9M6KfuKOE8aeW+E0SS7Ug7UHZlzEY+GuE//0zop+4o4Txp5b4TRJLtSDtQdmXMRj4a4T5OjQM7NuWY8RSq0Ca2RI235AIYPBmGgBrhPk6NAzs25ZjxFKrQJrZEjbfkAhg8GYaAGuE+To0DOzblmPEUqtAmtkSNt+QCGDwZhoAa4T7PZbZs/9SbpdgANMEQ8dHeHtgBUeAsw9vgPs9ltmz/1Jul2AA0wRDx0d4e2AFR4CzD2+A+z2W2bP/Um6XYADTBEPHR3h7YAVHgLMPb4D2owBNmJWRvv7qjzQoEM7j+lo0O36b9DRrhZTE6dDg6LZGYmOd7p/sxOnkxOnJl
Copy after login


这份是通过bencode解码后的nodes数据,也就是在这个数据中分成每份26字节,从26字节中取出20字节的nid,4字节的ip,2字节的端口:
P9LI9UagRY0oDfVScSnuyKZHmjRO68KLdlc/0sj1RqBFjSgN9VJxKe7IpkeaNE7rwot2Vz/SyPVGoEWNKA31UnEp7simR5o0TuvCi3ZXP/wj7jU8hMYdclU8RKIZNM7tvZSxt+rIH5A//CPuNTyExh1yVTxEohk0zu29lLG36sgfkD/8I+41PITGHXJVPESiGTTO7b2UsbfqyB+QP/9M6KfuKOE8aeW+E0SS7Ug7UHZlzEY+GuE//0zop+4o4Txp5b4TRJLtSDtQdmXMRj4a4T//TOin7ijhPGnlvhNEku1IO1B2ZcxGPhrhPk6NAzs25ZjxFKrQJrZEjbfkAhg8GYaAGuE+To0DOzblmPEUqtAmtkSNt+QCGDwZhoAa4T5OjQM7NuWY8RSq0Ca2RI235AIYPBmGgBrhPs9ltmz/1Jul2AA0wRDx0d4e2AFR4CzD2+A+z2W2bP/Um6XYADTBEPHR3h7YAVHgLMPb4D7PZbZs/9SbpdgANMEQ8dHeHtgBUeAsw9vgPajAE2YlZG+/uqPNCgQzuP6WjQ7fpv0NGuE=
Copy after login

$s = 'P9LI9UagRY0oDfVScSnuyKZHmjRO68KLdlc/0sj1RqBFjSgN9VJxKe7IpkeaNE7rwot2Vz/SyPVGoEWNKA31UnEp7simR5o0TuvCi3ZXP/wj7jU8hMYdclU8RKIZNM7tvZSxt+rIH5A//CPuNTyExh1yVTxEohk0zu29lLG36sgfkD/8I+41PITGHXJVPESiGTTO7b2UsbfqyB+QP/9M6KfuKOE8aeW+E0SS7Ug7UHZlzEY+GuE//0zop+4o4Txp5b4TRJLtSDtQdmXMRj4a4T//TOin7ijhPGnlvhNEku1IO1B2ZcxGPhrhPk6NAzs25ZjxFKrQJrZEjbfkAhg8GYaAGuE+To0DOzblmPEUqtAmtkSNt+QCGDwZhoAa4T5OjQM7NuWY8RSq0Ca2RI235AIYPBmGgBrhPs9ltmz/1Jul2AA0wRDx0d4e2AFR4CzD2+A+z2W2bP/Um6XYADTBEPHR3h7YAVHgLMPb4D7PZbZs/9SbpdgANMEQ8dHeHtgBUeAsw9vgPajAE2YlZG+/uqPNCgQzuP6WjQ7fpv0NGuE=';$s = base64_decode($s);foreach(str_split($s, 26) as $s) {  $r = unpack('a20n/Nip/np', $s);  $r['ip'] = long2ip($r['ip']);  print_r($r);}
Copy after login
Copy after login
Array(    [n] => ?&Ograve;&Egrave;&otilde;F E?(&otilde;Rq)&icirc;&Egrave;&brvbar;G?4    [ip] => 78.235.194.139    [p] => 30295)Array(    [n] => ?&Ograve;&Egrave;&otilde;F E?(&otilde;Rq)&icirc;&Egrave;&brvbar;G?4    [ip] => 78.235.194.139    [p] => 30295)Array(    [n] => ?&Ograve;&Egrave;&otilde;F E?(&otilde;Rq)&icirc;&Egrave;&brvbar;G?4    [ip] => 78.235.194.139    [p] => 30295)Array(    [n] => ?&uuml;#&icirc;5<?&AElig;rU<D&cent;4&Icirc;&iacute;&frac12;”    [ip] => 177.183.234.200    [p] => 8080)Array(    [n] => ?&uuml;#&icirc;5<?&AElig;rU<D&cent;4&Icirc;&iacute;&frac12;”    [ip] => 177.183.234.200    [p] => 8080)Array(    [n] => ?&uuml;#&icirc;5<?&AElig;rU<D&cent;4&Icirc;&iacute;&frac12;”    [ip] => 177.183.234.200    [p] => 8080)Array(    [n] => ?&yuml;L&egrave;&sect;&icirc;(&aacute;<i&aring;&frac34;D’&iacute;H;Pv    [ip] => 101.204.70.62    [p] => 6881)Array(    [n] => ?&yuml;L&egrave;&sect;&icirc;(&aacute;<i&aring;&frac34;D’&iacute;H;Pv    [ip] => 101.204.70.62    [p] => 6881)Array(    [n] => ?&yuml;L&egrave;&sect;&icirc;(&aacute;<i&aring;&frac34;D’&iacute;H;Pv    [ip] => 101.204.70.62    [p] => 6881)Array(    [n] => >N?;6&aring;?&ntilde;&ordf;?&&para;D?&middot;&auml;    [ip] => 60.25.134.128    [p] => 6881)Array(    [n] => >N?;6&aring;?&ntilde;&ordf;?&&para;D?&middot;&auml;    [ip] => 60.25.134.128    [p] => 6881)Array(    [n] => >N?;6&aring;?&ntilde;&ordf;?&&para;D?&middot;&auml;    [ip] => 60.25.134.128    [p] => 6881)Array(    [n] => >&Iuml;e&para;l&yuml;&Ocirc;?&yen;&Oslash;4&Aacute;&ntilde;&Ntilde;?&Oslash;    [ip] => 81.224.44.195    [p] => 56288)Array(    [n] => >&Iuml;e&para;l&yuml;&Ocirc;?&yen;&Oslash;4&Aacute;&ntilde;&Ntilde;?&Oslash;    [ip] => 81.224.44.195    [p] => 56288)Array(    [n] => >&Iuml;e&para;l&yuml;&Ocirc;?&yen;&Oslash;4&Aacute;&ntilde;&Ntilde;?&Oslash;    [ip] => 81.224.44.195    [p] => 56288)Array(    [n] => =&uml;&Agrave;f%do&iquest;&ordm;&pound;&Iacute;3&cedil;???    [ip] => 223.166.253.13    [p] => 6881)
Copy after login
Copy after login
应该是没有问题的

$s = 'P9LI9UagRY0oDfVScSnuyKZHmjRO68KLdlc/0sj1RqBFjSgN9VJxKe7IpkeaNE7rwot2Vz/SyPVGoEWNKA31UnEp7simR5o0TuvCi3ZXP/wj7jU8hMYdclU8RKIZNM7tvZSxt+rIH5A//CPuNTyExh1yVTxEohk0zu29lLG36sgfkD/8I+41PITGHXJVPESiGTTO7b2UsbfqyB+QP/9M6KfuKOE8aeW+E0SS7Ug7UHZlzEY+GuE//0zop+4o4Txp5b4TRJLtSDtQdmXMRj4a4T//TOin7ijhPGnlvhNEku1IO1B2ZcxGPhrhPk6NAzs25ZjxFKrQJrZEjbfkAhg8GYaAGuE+To0DOzblmPEUqtAmtkSNt+QCGDwZhoAa4T5OjQM7NuWY8RSq0Ca2RI235AIYPBmGgBrhPs9ltmz/1Jul2AA0wRDx0d4e2AFR4CzD2+A+z2W2bP/Um6XYADTBEPHR3h7YAVHgLMPb4D7PZbZs/9SbpdgANMEQ8dHeHtgBUeAsw9vgPajAE2YlZG+/uqPNCgQzuP6WjQ7fpv0NGuE=';$s = base64_decode($s);foreach(str_split($s, 26) as $s) {  $r = unpack('a20n/Nip/np', $s);  $r['ip'] = long2ip($r['ip']);  print_r($r);}
Copy after login
Copy after login
Array(    [n] => ?&Ograve;&Egrave;&otilde;F E?(&otilde;Rq)&icirc;&Egrave;&brvbar;G?4    [ip] => 78.235.194.139    [p] => 30295)Array(    [n] => ?&Ograve;&Egrave;&otilde;F E?(&otilde;Rq)&icirc;&Egrave;&brvbar;G?4    [ip] => 78.235.194.139    [p] => 30295)Array(    [n] => ?&Ograve;&Egrave;&otilde;F E?(&otilde;Rq)&icirc;&Egrave;&brvbar;G?4    [ip] => 78.235.194.139    [p] => 30295)Array(    [n] => ?&uuml;#&icirc;5<?&AElig;rU<D&cent;4&Icirc;&iacute;&frac12;”    [ip] => 177.183.234.200    [p] => 8080)Array(    [n] => ?&uuml;#&icirc;5<?&AElig;rU<D&cent;4&Icirc;&iacute;&frac12;”    [ip] => 177.183.234.200    [p] => 8080)Array(    [n] => ?&uuml;#&icirc;5<?&AElig;rU<D&cent;4&Icirc;&iacute;&frac12;”    [ip] => 177.183.234.200    [p] => 8080)Array(    [n] => ?&yuml;L&egrave;&sect;&icirc;(&aacute;<i&aring;&frac34;D’&iacute;H;Pv    [ip] => 101.204.70.62    [p] => 6881)Array(    [n] => ?&yuml;L&egrave;&sect;&icirc;(&aacute;<i&aring;&frac34;D’&iacute;H;Pv    [ip] => 101.204.70.62    [p] => 6881)Array(    [n] => ?&yuml;L&egrave;&sect;&icirc;(&aacute;<i&aring;&frac34;D’&iacute;H;Pv    [ip] => 101.204.70.62    [p] => 6881)Array(    [n] => >N?;6&aring;?&ntilde;&ordf;?&&para;D?&middot;&auml;    [ip] => 60.25.134.128    [p] => 6881)Array(    [n] => >N?;6&aring;?&ntilde;&ordf;?&&para;D?&middot;&auml;    [ip] => 60.25.134.128    [p] => 6881)Array(    [n] => >N?;6&aring;?&ntilde;&ordf;?&&para;D?&middot;&auml;    [ip] => 60.25.134.128    [p] => 6881)Array(    [n] => >&Iuml;e&para;l&yuml;&Ocirc;?&yen;&Oslash;4&Aacute;&ntilde;&Ntilde;?&Oslash;    [ip] => 81.224.44.195    [p] => 56288)Array(    [n] => >&Iuml;e&para;l&yuml;&Ocirc;?&yen;&Oslash;4&Aacute;&ntilde;&Ntilde;?&Oslash;    [ip] => 81.224.44.195    [p] => 56288)Array(    [n] => >&Iuml;e&para;l&yuml;&Ocirc;?&yen;&Oslash;4&Aacute;&ntilde;&Ntilde;?&Oslash;    [ip] => 81.224.44.195    [p] => 56288)Array(    [n] => =&uml;&Agrave;f%do&iquest;&ordm;&pound;&Iacute;3&cedil;???    [ip] => 223.166.253.13    [p] => 6881)
Copy after login
Copy after login
应该是没有问题的



非常非常感谢,看来是我一开始截取的时候就截取错了,所以获取到的结果才会不对,真的太感谢了!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

How does session hijacking work and how can you mitigate it in PHP? How does session hijacking work and how can you mitigate it in PHP? Apr 06, 2025 am 12:02 AM

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

Describe the SOLID principles and how they apply to PHP development. Describe the SOLID principles and how they apply to PHP development. Apr 03, 2025 am 12:04 AM

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? How to debug CLI mode in PHPStorm? Apr 01, 2025 pm 02:57 PM

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to send a POST request containing JSON data using PHP's cURL library? How to send a POST request containing JSON data using PHP's cURL library? Apr 01, 2025 pm 03:12 PM

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

See all articles