


PHP extension package: a brief introduction to the extension package that can replace PHP native functions
The content of this article is about PHP expansion packages: a brief introduction to expansion packages that can replace PHP native functions. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. .
Although programmers are making wheels all the time, there are also differences in efficiency in making wheels. Only by using good wheels can you create a good "??"
guzzlehttp/guzzle
composer require guzzlehttp/guzzle
You can use guzzlehttp to completely replace curl, file_get_content, fopen and other functions. This expansion pack is extremely easy to use. Let’s look at the comparison in terms of code size.
php_curl
<?php //初始化 $curl = curl_init(); //设置抓取的url curl_setopt($curl, CURLOPT_URL, 'http://www.baidu.com'); //设置头文件的信息作为数据流输出 curl_setopt($curl, CURLOPT_HEADER, 1); //设置获取的信息以文件流的形式返回,而不是直接输出。 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //设置post方式提交 curl_setopt($curl, CURLOPT_POST, 1); //设置post数据 $post_data = array( "username" => "coder", "password" => "12345" ); curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data); //执行命令 $data = curl_exec($curl); //关闭URL请求 curl_close($curl); //显示获得的数据 print_r($data);
guzzlehttp
use GuzzleHttp\Client; $client = new GuzzleHttp\Client(); $response = $client->request('POST', 'http://www.baidu.com', [ 'form_params' => [ 'username' => 'coder', 'password' => '12345' ] ]); print_r($response);
jenssegers/date
composer require jenssegers/date
Use this extension package to let the php program The implementation of date-related requirements by employees is more concise and simple. Please see the comparison below
php_date
date("Ym", strtotime("-1 day")); //获取前一天的日期 date("Ym", strtotime("+1 day")); //获取后一天的日期
jenssegers_date
(new Date('-1 day'))->format ('Ym'); // 获取前一天的日期 (new Date('+1 day'))->format ('Ym'); //获取后一天的日期
It is obvious that the new method is more intuitive for date processing. Of course, this is a simple application, and it will be more advantageous in complex date calculations.
chumper/zipper
composer require chumper/zipper
Using this package can simplify the complexity of using the zip function of PHP itself
php_zip
<?php $resource = zip_open($filename); while($zip = zip_read($resource)) { if(zip_entry_open($resource, $zip)) { $file_content = zip_entry_name($zip); $file_name = substr($file_content, strrpos($file_content, '/') +1); if(!is_dir($file_name) && $file_name) { $save_path = $dir .'/'. $file_name; if(file_exists($save_path)) { echo '文件夹内已存在文件 "' . $file_name . '" <pre />'; }else { echo $file_name . '<pre />'; $file_size = zip_entry_filesize($zip); $file = zip_entry_read($zip, $file_size); file_put_contents($save_path, $file); zip_entry_close($zip); } } } } zip_close($resource);
chumper/zipper
Zipper::make('test.zip')->folder('test')->extractTo('foo');
It’s so obvious that I don’t think I need to explain anything.
anchu/ftp
composer require anchu/ftp
This package can simplify the process of php's own ftp upload code
php_ftp
<?php $host = '10.0.0.42'; $user = 'uftp'; $pwd = 'uftp'; // 进行ftp连接,根据port是否设置,传递的参数会不同 if(empty($port)){ $f_conn = ftp_connect($host); }else{ $f_conn = ftp_connect($host, $port); } if(!$f_conn){ echo "connect fail\n"; exit(1); } echo "connect success\n"; // 进行ftp登录,使用给定的ftp登录用户名和密码进行login $f_login = ftp_login($f_conn,$user,$pwd); if(!$f_login){ echo "login fail\n"; exit(1); } echo "login success\n"; // 获取当前所在的ftp目录 $in_dir = ftp_pwd($f_conn); if(!$in_dir){ echo "get dir info fail\n"; exit(1); } echo "$in_dir\n"; // 获取当前所在ftp目录下包含的目录与文件 $exist_dir = ftp_nlist($f_conn, ftp_pwd($f_conn)); print_r($exist_dir); // 要求是按照日期在ftp目录下创建文件夹作为文件上传存放目录 echo date("Ymd")."\n"; $dir_name = date("Ymd"); // 检查ftp目录下是否已存在当前日期的文件夹,如不存在则进行创建 if(!in_array("$in_dir/$dir_name", $exist_dir)){ if(!ftp_mkdir($f_conn, $dir_name)){ echo "mkdir fail\n"; exit(1); }else{ echo "mkdir $dir_name success\n"; } } // 切换目录 if(!ftp_chdir($f_conn, $dir_name)){ echo "chdir fail\n"; exit(1); }else{ echo "chdir $dir_name success\n"; } // 进行文件上传 $result = ftp_put($f_conn, 'bbb.mp3', '/root/liang/ftp/bbb.mp3', FTP_BINARY); if(!$result){ echo "upload file fail\n"; exit(1); }else{ echo "upload file success\n"; exit(0); }
anchu/ ftp
Config::set('ftp.connections.key', array( 'host' => '', 'username' => '', 'password' => '', 'passive' => false, 'secure' => false, )); FTP::uploadFile($fileFrom,$fileTo,$mode)
Related recommendations:
redis PHP extension package installation method
##php Install xdebug extension, phpxdebug extension
php extension and embedding--c extension development helloworld
The above is the detailed content of PHP extension package: a brief introduction to the extension package that can replace PHP native functions. For more information, please follow other related articles on the PHP Chinese website!

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

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

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

Alipay PHP...

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,

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.

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 debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

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...

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.
