<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>PHP on seth-shi</title><link>https://sethix.com/tags/php/</link><description>Recent content in PHP on seth-shi</description><generator>Hugo -- gohugo.io</generator><language>en</language><lastBuildDate>Tue, 07 Jan 2025 14:19:05 +0800</lastBuildDate><atom:link href="https://sethix.com/tags/php/index.xml" rel="self" type="application/rss+xml"/><item><title>Troubleshooting High Memory Usage in PHP Queue Service</title><link>https://sethix.com/posts/2025010714/</link><pubDate>Tue, 07 Jan 2025 14:19:05 +0800</pubDate><guid>https://sethix.com/posts/2025010714/</guid><description>The operations team reported recurring OOM (Out-Of-Memory) restarts in a container pod. Monitoring data showed periodic memory spikes: 1.png The service in question handles video composition via queue jobs. It uses shell_exec to invoke commands like ffmpeg and spleeter for audio processing and quality adjustments.
Since external command execution isn&amp;rsquo;t trackable through PHP&amp;rsquo;s memory monitoring, we used atop for detailed logging.
Service Setup ## Installation apt update &amp;amp;&amp;amp; apt install -y atop ## Modify the configuration file cat /etc/default/atop LOGOPTS=&amp;#34;&amp;#34; LOGINTERVAL=1 # Set to 1s for granular monitoring LOGGENERATIONS=28 # Retain logs for 28 days LOGPATH=/var/log/atop ## Start service systemctl start atop Diagnosis Process Alibaba Cloud monitoring showed a memory spike at 16:20:30: img.</description></item><item><title>Upgrading from Laravel5 to Laravel10: A Journey with Octane Containerization and Horizon Integration</title><link>https://sethix.com/posts/2024042811/</link><pubDate>Sun, 28 Apr 2024 11:02:51 +0800</pubDate><guid>https://sethix.com/posts/2024042811/</guid><description>While working on upgrading PHP versions, I took the opportunity to upgrade https://github.com/seth-shi/monday-shop from Laravel5 to Laravel10. Existing Solutions Paid option: https://laravelshift.com/ Open-source helper: https://laravel-upgrade-helper.github.io/ Upgrade Process Project Preparation Assume project path: /var/www/monday-shop Create a new Laravel10 project within the same directory: composer create-project laravel/laravel=10.* laravel10 New project path: /var/www/monday-shop/laravel10 Dependency Management Update dependencies: Merge require and require-dev sections from /var/www/monday-shop/laravel10/composer.json Delete old /var/www/monday-shop/composer.lock Resolve dependency conflicts: # Example conflict resolution composer install # Handle version conflicts iteratively Verify unused dependencies with composer depends xxx/xxxx File Migration Copy core files from new Laravel10 project: # Maintain directory structure while preserving custom modifications ├─app ├─bootstrap ├─config ├─database ├─public ├─resources ├─routes ├─storage ├─tests Process files folder-by-folder, comparing with custom implementations Error Resolution Start development server: php artisan serve Monitor storage/logs for errors Install missing helpers: composer require laravel/helpers Containerization with Octane Replace legacy laravel-s with official Octane: composer require laravel/octane Implement containerization using laravel-octane-dockerfile Key Configuration Files .</description></item><item><title>PHP-roadrunner Stress Testing and Configuration Tuning</title><link>https://sethix.com/posts/2024042417/</link><pubDate>Wed, 24 Apr 2024 17:50:27 +0800</pubDate><guid>https://sethix.com/posts/2024042417/</guid><description>Pod Configuration CPU Memory 0.5 512M Testing Tool Alibaba Cloud PTS Concurrency Duration Source Test Endpoint 100 2 min Public /api/welcome Note: 100 concurrency was determined after initial testing as the maximum load the pod could handle without errors (200 concurrency caused significant RT increases).
Service Startup RoadRunner architecture:
RoadRunner Architecture Laravel Octane natively supports RoadRunner. Start the HTTP service with:
php artisan octane:start --server=roadrunner --host=0.0.0.0 --port=8080 --rpc-port=6001 --workers=1 --log-level=warn --max-requests=50000 --rr-config=/var/www/.</description></item><item><title>Using gRPC Client for System Login in PHP Backend dcat-admin</title><link>https://sethix.com/posts/2023102010/</link><pubDate>Fri, 20 Oct 2023 10:38:05 +0800</pubDate><guid>https://sethix.com/posts/2023102010/</guid><description>Introduction The company has implemented a unified account center service using go-zero Some project backends built with dcat-admin need to authenticate users through this account center, documenting the implementation process Environment Setup Protobuf binary files from https://github.com/protocolbuffers/protobuf/releases Follow official documentation for installation: https://cloud.google.com/php/grpc?hl=zh-cn#windows For Windows: Download corresponding PHP version DLL from https://pecl.php.net/package/grpc Install packages: composer require &amp;#34;grpc/grpc:^1.38&amp;#34; composer require &amp;#34;google/protobuf:^3.17&amp;#34; For Docker (using mlocati/docker-php-extension-installer): RUN install-php-extensions grpc Generate PHP gRPC code requires grpc_php_plugin: Official guide: https://github.</description></item><item><title>Force Returning Empty Data When MySQL Unexpectedly Crashes in Laravel</title><link>https://sethix.com/posts/2023062514/</link><pubDate>Sun, 25 Jun 2023 14:14:01 +0800</pubDate><guid>https://sethix.com/posts/2023062514/</guid><description>Background We previously encountered an issue where the service completely crashed when MySQL went down, with Redis failing to handle any requests. The normal business query logic is: Get data from Redis first, return if available If Redis has no data, query MySQL Write the retrieved data to Redis Return data Problem Analysis Redis itself wasn&amp;rsquo;t the issue - the problem occurred at step 2 When querying MySQL with the database service down, requests get blocked Blocking timeout leads to exceptions, preventing step 3 from executing Subsequent requests continue trying to connect to MySQL, creating infinite blocking that overloads the application servers Solution Our solution (may not fit all scenarios): Force caching empty data in Redis when MySQL crashes, allowing partial empty responses instead of service failure Implementation Approach Set appropriate MySQL connection timeout mysqlnd.</description></item><item><title>Advertising Attribution - A Comprehensive Guide to Attribution Architecture Implementation</title><link>https://sethix.com/posts/2023011214/</link><pubDate>Thu, 12 Jan 2023 14:58:55 +0800</pubDate><guid>https://sethix.com/posts/2023011214/</guid><description>Explanation Many concepts in this article reference insights from Sensors Data documentation. Attribution Methods Self-Attribution
Tracked by ad platforms. Some platforms receive app-open callbacks from users and perform attribution internally. Others like Huawei store attribution data locally during app installation, retrievable during first launch. Impression Attribution
Rarely used due to massive data volumes. Click Attribution (Most Common)
Attributes conversions to the last ad click before conversion. Attribution Models Last-Touch Model (Most Common)</description></item><item><title>Using laravel-s in Docker (Including Queue Usage)</title><link>https://sethix.com/posts/2022030118/</link><pubDate>Tue, 01 Mar 2022 18:12:32 +0800</pubDate><guid>https://sethix.com/posts/2022030118/</guid><description>Environment Configuration FROM phpswoole/swoole:php7.4-alpine # A script for installing PHP extensions COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ RUN install-php-extensions pcntl redis pdo_mysql WORKDIR /var/www COPY . . RUN chmod -R 0777 storage &amp;amp;&amp;amp; \ chmod -R 0777 bootstrap/cache &amp;amp;&amp;amp; \ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ &amp;amp;&amp;amp; \ composer install --optimize-autoloader --no-dev &amp;amp;&amp;amp; \ php artisan config:cache &amp;amp;&amp;amp; \ php artisan route:cache &amp;amp;&amp;amp; \ php artisan view:cache &amp;amp;&amp;amp; \ php artisan laravels publish --no-interaction CMD [&amp;#34;php&amp;#34;, &amp;#34;bin/laravels&amp;#34;, &amp;#34;start&amp;#34;, &amp;#34;--env=product&amp;#34;] Deployment ## Build the image docker build .</description></item><item><title>Advanced Usage of Pyroscope for Go and PHP Performance Analysis</title><link>https://sethix.com/posts/2022021516/</link><pubDate>Tue, 15 Feb 2022 16:23:40 +0800</pubDate><guid>https://sethix.com/posts/2022021516/</guid><description>Installation Many online tutorials simply use a single Docker command:
docker run -it -p 4040:4040 --restart=always pyroscope/pyroscope:latest server However, this basic installation lacks crucial configurations: no authentication for the data dashboard, no API reporting restrictions (e.g., limiting reporting via API keys), and no data persistence after container destruction. Here&amp;rsquo;s a better approach using docker-compose.yml: version: &amp;#34;3&amp;#34; services: pyroscope: image: &amp;#34;pyroscope/pyroscope:latest&amp;#34; ports: - &amp;#34;4040:4040&amp;#34; command: - &amp;#34;server&amp;#34; environment: ## Enforce API key authentication for data ingestion - PYROSCOPE_AUTH_INGESTION_ENABLED=true ## Enable login for web dashboard - PYROSCOPE_AUTH_INTERNAL_ENABLED=true volumes: ## Persistent data storage - .</description></item><item><title>Troubleshooting Laravel-S Memory Leak with Swoole Tracker</title><link>https://sethix.com/posts/2022010510/</link><pubDate>Wed, 05 Jan 2022 10:54:45 +0800</pubDate><guid>https://sethix.com/posts/2022010510/</guid><description>Environment Setup Built using swoole:alpine Docker image FROM phpswoole/swoole:php7.4-alpine RUN sed -i &amp;#39;s/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g&amp;#39; /etc/apk/repositories &amp;amp;&amp;amp; cat /etc/apk/repositories # Quick PHP extension installation COPY --from=mlocati/php-extension-installer /usr/bin/install-php-extensions /usr/local/bin/ RUN install-php-extensions pcntl redis pdo_mysql WORKDIR /var/www COPY . . RUN chmod -R 0777 storage &amp;amp;&amp;amp; \ chmod -R 0777 bootstrap/cache &amp;amp;&amp;amp; \ composer config -g repo.packagist composer https://mirrors.aliyun.com/composer/ &amp;amp;&amp;amp; \ composer install --optimize-autoloader --no-dev &amp;amp;&amp;amp; \ php artisan config:cache &amp;amp;&amp;amp; \ php artisan route:cache &amp;amp;&amp;amp; \ php artisan view:cache &amp;amp;&amp;amp; \ php artisan laravels publish --no-interaction CMD [&amp;#34;php&amp;#34;, &amp;#34;bin/laravels&amp;#34;, &amp;#34;start&amp;#34;, &amp;#34;--env=product&amp;#34;] For initial setup, comment out the last two lines in Dockerfile: docker build .</description></item><item><title>Containerizing All Services: Running PHP Code in Containers with Laravel-S</title><link>https://sethix.com/posts/2021102416/</link><pubDate>Sun, 24 Oct 2021 16:05:45 +0800</pubDate><guid>https://sethix.com/posts/2021102416/</guid><description>Preface Recently containerized all Go programs on the server for deployment Combined with CODING&amp;rsquo;s CI/CD, deployment has become extremely pleasant But there were still several PHP projects remaining on the server Blog (Originally built with WordPress) Deploy Nginx and PHP containers, then reverse proxy via host machine Discovered Hugo (similar to Hexo), a static site generator Migrated blog to Hugo with fast builds and real-time previews Now runs in a single Nginx container with host reverse proxy Details: My Blog DreamNote Admin (Laravel) Original Nginx + PHP-FPM container approach Switched to persistent PHP runtime using laravel-s (supports dcat-admin) Official Swoole container docker-swoole with custom Dockerfile: FROM phpswoole/swoole:php7.</description></item><item><title>PHP Source Code Reading</title><link>https://sethix.com/posts/2021080310/</link><pubDate>Tue, 03 Aug 2021 10:51:57 +0800</pubDate><guid>https://sethix.com/posts/2021080310/</guid><description>Getting Started (Environment Setup) Create a project directory and add Dockerfile FROM centos:7 # Install dependencies RUN yum -y install gcc gcc-c++ gdb autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gd gd2 gd-devel gd2-devel perl-CPAN pcre-devel libicu-devel wget # Download specific PHP version RUN wget -O /tmp/php.</description></item><item><title>A Slow API Incident Leading to Database Query Testing and Fully Automated API Test Assertions</title><link>https://sethix.com/posts/2021072215/</link><pubDate>Thu, 22 Jul 2021 15:08:54 +0800</pubDate><guid>https://sethix.com/posts/2021072215/</guid><description>Today during client-side testing, feedback indicated a slow API response. With the responsible colleague on leave, I investigated the project and confirmed the issue.
Added SQL logging in the controller: # SQL logging DB::listen(fn(QueryExecuted $query) =&amp;gt; Log::info($query-&amp;gt;sql)); # Log output [2021-07-22 12:46:15] local.INFO: select * from `albums` where `albums`.`id` = ? and `albums`.`deleted_at` is null limit 1 ... (repeated 24 times) The logs revealed multiple identical queries - a classic N+1 problem caused by missing eager loading Database query pseudocode: class Controller { public function index() { $models = Model::query()-&amp;gt;limit(20)-&amp;gt;get(); return ModelsResource::collection($models); } } class ModelsResource extends JsonResource { public function toArray($request) { return [ &amp;#39;id&amp;#39; =&amp;gt; $this-&amp;gt;id, &amp;#39;name&amp;#39; =&amp;gt; $this-&amp;gt;title, &amp;#39;album_id&amp;#39; =&amp;gt; $this-&amp;gt;album_id, // Problematic line &amp;#39;album_name&amp;#39; =&amp;gt; $this-&amp;gt;album-&amp;gt;title, ]; } } The resource accessed the album relationship without eager loading Solution: Add eager loading $models = Model::query()-&amp;gt;with(&amp;#39;album&amp;#39;)-&amp;gt;limit(20)-&amp;gt;get(); Prevention Strategies Problem detection is costly - better to prevent through automation Implemented HTTP testing with SQL query monitoring in base TestCase: public function json($method, $uri, array $data = [], array $headers = []) { $maxCount = 10; DB::enableQueryLog(); $response = parent::json($method, $uri, $data, $headers); $queries = collect(DB::getQueryLog())-&amp;gt;pluck(&amp;#39;query&amp;#39;); $this-&amp;gt;assertLessThan( $maxCount, $queries-&amp;gt;count(), sprintf(&amp;#34;Endpoint:%s[%s], SQL:%d\r\n%s&amp;#34;, $uri, $method, $maxCount, $queries-&amp;gt;implode(&amp;#34;\r\n&amp;#34;)) ); DB::flushQueryLog(); return $response; } Enhanced validation using unique query comparison: $duplicateQueries = $queries-&amp;gt;count() - $queries-&amp;gt;unique()-&amp;gt;count(); $this-&amp;gt;assertLessThan($maxDuplicates, $duplicateQueries, &amp;#34;Excessive duplicate queries&amp;#34;); Route coverage validation via custom test suite: &amp;lt;testsuite name=&amp;#34;End&amp;#34;&amp;gt; &amp;lt;file&amp;gt;tests/EndApiTest.</description></item><item><title>Solving Custom Page Refresh Issue with Admin PJAX by Breaking Out of Conventional Thinking</title><link>https://sethix.com/posts/2021070713/</link><pubDate>Wed, 07 Jul 2021 13:04:58 +0800</pubDate><guid>https://sethix.com/posts/2021070713/</guid><description>Using laravel-admin for backend development, we added a notification bell in the top-right corner Laravel Admin Notification Interface As shown above, clicking the bell icon should clear notifications and refresh the current page. Implemented using laravel-admin&amp;rsquo;s action: &amp;lt;?php namespace App\Admin\Actions\Custom; use Encore\Admin\Actions\Action; use Illuminate\Http\Request; class MarkNotificationRead extends Action { protected $selector = &amp;#39;.mark-notification-read&amp;#39;; public function handle(Request $request) { // forget notifications return $this-&amp;gt;response()-&amp;gt;success(&amp;#34;Marked all as read&amp;#34;)-&amp;gt;refresh(); } public function html() { // get notifications $count = 1; $countText = &amp;#34;&amp;lt;span class=\&amp;#34;label label-danger\&amp;#34;&amp;gt;{$count}&amp;lt;/span&amp;gt;&amp;#34;; return &amp;#34;&amp;lt;li title=&amp;#39;Click to mark as read&amp;#39;&amp;gt; &amp;lt;a href=\&amp;#34;#\&amp;#34; class=&amp;#39;mark-notification-read&amp;#39;&amp;gt; &amp;lt;i data-count=&amp;#39;{$count}&amp;#39; id=&amp;#39;notification&amp;#39; class=\&amp;#34;fa fa-bell fa-rotate-0\&amp;#34;&amp;gt;&amp;lt;/i&amp;gt; {$countText} &amp;lt;/a&amp;gt; &amp;lt;/li&amp;gt;&amp;#34;; } } The pseudo-code above implements the notification feature.</description></item><item><title>A Bug Caused by Static Variables in Laravel Queues</title><link>https://sethix.com/posts/2021070612/</link><pubDate>Tue, 06 Jul 2021 12:43:13 +0800</pubDate><guid>https://sethix.com/posts/2021070612/</guid><description>Environment PHP_VERSION=7.4 laravel/framework: ^7.0 Static Variables In many programming languages, static variables are defined as variables that: Have the same lifecycle as the program Are initialized only once However, in PHP&amp;rsquo;s common runtime environment (php-fpm mode), processes get recycled after each request, so static variables don&amp;rsquo;t persist in memory (only effective during the current request) Official PHP documentation states: &amp;ldquo;Another important feature of variable scoping is the static variable. A static variable exists only in a local function scope, but it does not lose its value when program execution leaves this scope.</description></item><item><title>A Lesson Learned from Laradock Cron Job Failures</title><link>https://sethix.com/posts/2021070211/</link><pubDate>Fri, 02 Jul 2021 11:25:44 +0800</pubDate><guid>https://sethix.com/posts/2021070211/</guid><description>Debugging Steps The cron jobs in laradock are executed in the workspace container. Check logs using: docker-compose logs -f workspace Sample log output:
Jul 2 12:26:59 9b6ec4d18dd1 syslog-ng[12]: syslog-ng starting up; version=&amp;#39;3.13.2&amp;#39; workspace_1 | *** Booting runit daemon... workspace_1 | *** Runit started as PID 20 workspace_1 | Jul 2 12:27:00 9b6ec4d18dd1 cron[23]: (CRON) INFO (pidfile fd = 3) ... Enter the container: docker-compose exec workspace bash Test cron job execution without suppressing output: /usr/bin/php /var/www/artisan schedule:run Permission Issues Logs in /storage/logs showed permission errors when created by root user.</description></item><item><title>How to Remove the Core Service - Views in Laravel</title><link>https://sethix.com/posts/2021052616/</link><pubDate>Wed, 26 May 2021 16:54:46 +0800</pubDate><guid>https://sethix.com/posts/2021052616/</guid><description>Previous article: Speed Up Your Service Performance by Reducing Service Provider Boot Time 2.0 A reader mentioned errors when directly removing the View service. This article demonstrates how to properly remove the View service. Step-by-Step Guide 1. Create a New Laravel Project composer create-project laravel/laravel=7.* laravel-demo 2. Modify the Default Route Edit routes/web.php to return JSON instead of a view:
Route::get(&amp;#39;/&amp;#39;, function () { return [ &amp;#39;code&amp;#39; =&amp;gt; 200, &amp;#39;msg&amp;#39; =&amp;gt; &amp;#39;hello&amp;#39; ]; }); 3.</description></item><item><title>Optimizing Laravel Performance by Reducing Service Providers Boot 2.0</title><link>https://sethix.com/posts/2021052512/</link><pubDate>Tue, 25 May 2021 12:08:42 +0800</pubDate><guid>https://sethix.com/posts/2021052512/</guid><description>Performance has always been one of the most discussed topics in Laravel, yet it has brought fresh perspectives to many PHP developers. Let&amp;rsquo;s optimize this framework once again.
Fundamentals (Common Knowledge) Use Redis drivers for caching, sessions, and queues Framework built-in caching: Route caching: php artisan route:cache Configuration caching: php artisan config:cache Implement caching based on API idempotency Upgrades OPcache: Enable it without hesitation Set opcache.validate_timestamps=0 to prevent automatic code updates in production (similar to compiled languages).</description></item><item><title>A Bug Caused by Combined Array Index Changes and Reference Parameters in PHP</title><link>https://sethix.com/posts/2021031412/</link><pubDate>Sun, 14 Mar 2021 12:07:42 +0800</pubDate><guid>https://sethix.com/posts/2021031412/</guid><description>Today, our team encountered a bug reported in the group chat. After cloning the project locally, I spent some time reproducing the issue.
Code Overview The following code causes the first item removal to convert a Collection into an object (JSON data): protected function transformJson($items) { return Collection::make($items) - -&amp;gt;values() -&amp;gt;where(&amp;#39;_remove_&amp;#39;, &amp;#39;0&amp;#39;) + -&amp;gt;values() -&amp;gt;map(fn($item) =&amp;gt; Arr::except($item, &amp;#39;_remove_&amp;#39;)) -&amp;gt;toJson(); In the API data retrieval logic, this function call pattern caused issues: public function index() { // $json={&amp;#34;1&amp;#34;:{&amp;#34;id&amp;#34;: 2}} $data = Collection::make($json); // Filtering converts indexes to 0-based $index = $this-&amp;gt;getRandomAd($data, [1]); // Returns null due to original key mismatch return $data-&amp;gt;get($index); } protected function getRandomAd(Collection $data, $notIn=[]) { $index = -1; if (count($notIn) &amp;gt; 0) { $data = $data-&amp;gt;filter(fn($item) =&amp;gt; !</description></item><item><title>Today Completed Refactoring All Internal APIs from PHP to Go</title><link>https://sethix.com/posts/2021010613/</link><pubDate>Wed, 06 Jan 2021 13:00:27 +0800</pubDate><guid>https://sethix.com/posts/2021010613/</guid><description>Previous API Request Flow User opens APP and requests business API Business API requests recommendation algorithm (with fault tolerance) Recommendation algorithm requests internal service Internal service provides business interface data to recommendation algorithm (e.g., manually configured recommendations) user -&amp;gt; API -&amp;gt; recommend service -&amp;gt; inner service user &amp;lt;- API &amp;lt;- recommend service &amp;lt;- inner service Originally built with Laravel, both API and inner service faced a single-point bottleneck. While API servers could scale horizontally, the inner service remained single-node.</description></item><item><title>Code Style and Quality Control in PHP Projects</title><link>https://sethix.com/posts/2020110215/</link><pubDate>Mon, 02 Nov 2020 15:32:57 +0800</pubDate><guid>https://sethix.com/posts/2020110215/</guid><description>Maintaining consistent code style is crucial in team development Configure PSR12 style in PHPStorm File -&amp;gt; Settings -&amp;gt; Editor-&amp;gt; Code Style -&amp;gt; Set from -&amp;gt; select PSR12 PhpStorm PSR12 Code Style Settings Using PHP_CodeSniffer for Code Style Checks Create phpcs.xml in project root for team-wide usage
Configuration notes:
Official documentation is limited - often requires debugging error messages Example: To disable end xxx() comments: Search source code for //end Locate PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting::ClosingDeclarationCommentSniff Remove &amp;lt;rule ref=&amp;quot;Squiz.</description></item><item><title>Making Concurrent Requests in PHP</title><link>https://sethix.com/posts/2020061715/</link><pubDate>Wed, 17 Jun 2020 15:04:16 +0800</pubDate><guid>https://sethix.com/posts/2020061715/</guid><description>PHP has always operated with a page-level lifecycle, where variables from previous requests aren&amp;rsquo;t shared with subsequent ones (unlike resident memory languages).
Most PHP code executes sequentially from top to bottom without callback capabilities The curl_multi_* function family enables &amp;ldquo;multi-threaded&amp;rdquo;-like behavior in PHP Recommended library for easier implementation: https://github.com/php-curl-class/php-curl-class Official concurrent request demo
&amp;lt;?php require __DIR__ . &amp;#39;/../vendor/autoload.php&amp;#39;; use Curl\MultiCurl; $urls = array( &amp;#39;tag3&amp;#39; =&amp;gt; &amp;#39;https://httpbin.org/post&amp;#39;, &amp;#39;tag4&amp;#39; =&amp;gt; &amp;#39;https://httpbin.org/get&amp;#39;, &amp;#39;tag5&amp;#39; =&amp;gt; &amp;#39;https://httpbin.</description></item><item><title>Getting Started with Docker and Docker-Compose</title><link>https://sethix.com/posts/2020060311/</link><pubDate>Wed, 03 Jun 2020 11:40:39 +0800</pubDate><guid>https://sethix.com/posts/2020060311/</guid><description>Many introductory articles are available online. I found these three particularly beginner-friendly:
Docker Tutorial Series from Basics to Advanced
Docker Tutorial Series (2): Docker Build
Docker Tutorial Series (3): Docker-Compose Docker You can directly pull an image using the command (take nginx as an example): docker pull nginx Dockerfile Essentially a text file describing how an image is built. After writing a Dockerfile, execute docker build to construct the image based on the instructions.</description></item><item><title>Install php-rdkafka Extension and Use Kafka for Logging</title><link>https://sethix.com/posts/2020050815/</link><pubDate>Fri, 08 May 2020 15:54:20 +0800</pubDate><guid>https://sethix.com/posts/2020050815/</guid><description>Recently, the user logs in our project have reached hundreds of millions. For convenience, we previously stored them directly in MySQL. Now big data requirements are pushing us to migrate these logs to Kafka.
Installation Development Environment Considerations Windows for local development Non-compiled installation for testing environment Production environment maintained by Ops team Linux Installation Ensure pecl is installed: pecl help version Install via pecl: sudo pecl install rdkafka Compile from Source Install dependencies (requires librdkafka):</description></item><item><title>Fake Requests in Slim for Your HTTP Testing Needs</title><link>https://sethix.com/posts/2019120417/</link><pubDate>Wed, 04 Dec 2019 17:21:20 +0800</pubDate><guid>https://sethix.com/posts/2019120417/</guid><description>When needing HTTP testing in code, Laravel has built-in functionality for this. With Slim, we have to build our own solution. After searching online for examples and finding limited resources, I decided to examine Laravel&amp;rsquo;s source code for inspiration. Discovered that the core idea is to mock a Request object and execute it to get response results. Implemented this approach in Slim framework accordingly. Setting Up Test Files Add autoload configuration in composer.</description></item><item><title>Using Middleware for Request Caching in Slim4</title><link>https://sethix.com/posts/2019112812/</link><pubDate>Thu, 28 Nov 2019 12:39:39 +0800</pubDate><guid>https://sethix.com/posts/2019112812/</guid><description>When developing web pages or API interfaces, we often encounter the following scenario:
A request is processed by querying the database and returning transformed data Some pages/interfaces with infrequent data changes (e.g. homepage) may experience performance issues under high traffic Solution: Cache processed content in storage like Redis before returning the response Subsequent requests first check the cache - return immediately if valid If cache expires, repeat steps [3-4] Here&amp;rsquo;s an implementation in Slim4 framework:</description></item><item><title>Slim - PHP - Laravel Performance Test</title><link>https://sethix.com/posts/2019112515/</link><pubDate>Mon, 25 Nov 2019 15:32:13 +0800</pubDate><guid>https://sethix.com/posts/2019112515/</guid><description>Test Environment Local Configuration (Win 10 i7-8565U 16G)(Nginx 1.15.11)(MySQL 5.5.62) Cloud Server (1 Core 2G)(Nginx 1.16.1)(MySQL 5.5.62) Performance Results Software Database Model Local QPS Cloud Server QPS Laravel 6.3.0 (with session) ORM 12.11 5.15 Laravel 6.3.0 (with session) PDO 13.85 5.31 Laravel 6.3.0 ORM 13.06 5.69 Laravel 6.3.0 PDO 13.98 5.89 Slim 4.3.0 PDO 41.04 43.65 PHP 7.1.9 Native PDO 52.85 51.81 Notes All tests performed using ApacheBench (ab) with command:</description></item><item><title>Implementation of Coupon Functionality</title><link>https://sethix.com/posts/2019090423/</link><pubDate>Wed, 04 Sep 2019 23:06:17 +0800</pubDate><guid>https://sethix.com/posts/2019090423/</guid><description>Recently I&amp;rsquo;ve developed several e-commerce projects, which inevitably involved designing coupon systems.
Since the Monday Mall project didn&amp;rsquo;t have this module, I decided to implement it during this period.
Referencing JD.com&amp;rsquo;s style, created a template like this:
Coupon Here&amp;rsquo;s the core logic:
First, we need a coupon template table Stores coupon templates for backend generation and user redemption Requires a separate user coupon table Table structure overview:
Coupon # Template Table `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `title` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT &amp;#39;Coupon title&amp;#39;, `amount` decimal(8,2) NOT NULL COMMENT &amp;#39;Discount amount&amp;#39;, `full_amount` decimal(8,2) NOT NULL COMMENT &amp;#39;Minimum purchase amount&amp;#39;, `score` int(10) unsigned NOT NULL DEFAULT &amp;#39;0&amp;#39; COMMENT &amp;#39;Redemption points required&amp;#39;, `start_date` date NOT NULL COMMENT &amp;#39;Start date&amp;#39;, `end_date` date NOT NULL COMMENT &amp;#39;Expiry date&amp;#39;, `created_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Creation time&amp;#39;, `updated_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Update time&amp;#39;, # User Coupon Table `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `user_id` int(10) unsigned COMMENT &amp;#39;User ID&amp;#39;, `title` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT &amp;#39;Coupon title&amp;#39;, `amount` decimal(8,2) NOT NULL COMMENT &amp;#39;Discount amount&amp;#39;, `full_amount` decimal(8,2) NOT NULL COMMENT &amp;#39;Minimum purchase amount&amp;#39;, `start_date` date NOT NULL COMMENT &amp;#39;Start date&amp;#39;, `end_date` date NOT NULL COMMENT &amp;#39;Expiry date&amp;#39;, `used_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Usage time&amp;#39;, `created_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Creation time&amp;#39;, `updated_at` timestamp NULL DEFAULT NULL COMMENT &amp;#39;Update time&amp;#39;, Key workflow:</description></item><item><title>[monday-shop] Issues and Solutions Encountered During Dependency Updates</title><link>https://sethix.com/posts/2019082411/</link><pubDate>Sat, 24 Aug 2019 11:17:03 +0800</pubDate><guid>https://sethix.com/posts/2019082411/</guid><description>This weekend, I updated the monday-shop system.
The most significant challenges came from upgrading laravel-admin to the latest version. This backend framework is particularly valuable as it allows developers to focus on core backend logic. First Issue: Composer Dependency Errors
Initial composer install failed due to locked mirror sources. Solved by switching to Alibaba Cloud Composer Mirror.
Laravel-admin Upgrade Challenges
monday-shop Key functionality affected:
Soft Delete (下架) Restore (上架) Version-Specific Problems:</description></item><item><title>Speed Up Your Framework: How to Reduce Service Provider Boot Time</title><link>https://sethix.com/posts/2019032219/</link><pubDate>Fri, 22 Mar 2019 19:32:57 +0800</pubDate><guid>https://sethix.com/posts/2019032219/</guid><description>Laravel has a powerful feature called service providers that makes it easy to access various services. However, this convenience comes at the cost of framework bloat. Here&amp;rsquo;s how to optimize unnecessary service providers.
Step 1: Identify Unnecessary Service Providers Run php artisan package:discover or composer dump-auto to see all auto-loaded service providers:
Service Providers Step 2: Conditionally Load Providers Example 1: Admin Panel Optimization The encore/laravel-admin package (a backend panel) boots on every request.</description></item><item><title>Converting UTC Time to Local Time</title><link>https://sethix.com/posts/2018111517/</link><pubDate>Thu, 15 Nov 2018 17:15:54 +0800</pubDate><guid>https://sethix.com/posts/2018111517/</guid><description>When working with UTC time formats that need conversion to local time (e.g., UTC+8), here&amp;rsquo;s a breakdown of the process for the input format yyyy-MM-ddTHH:mm:ss.SSSZ:
yyyy: 4-digit year MM: 2-digit month (01-12) dd: 2-digit day (01-31) T: Date/time separator HH: 24-hour format hour (00-23) mm: Minutes (00-59) ss: Seconds (00-59) SSS: Milliseconds (3 digits) Z: Timezone offset (e.g., +0100 for UTC+1) Example Conversion:
Input: 2018-01-01T12:00:00.000+0100 (UTC+1)
Local Output (UTC+8): 2018-01-01 19:00:00.</description></item><item><title>Quickly Set Up an LNMP Environment</title><link>https://sethix.com/posts/2018033111/</link><pubDate>Sat, 31 Mar 2018 11:55:27 +0800</pubDate><guid>https://sethix.com/posts/2018033111/</guid><description>Environment Specifications Linux version: CentOS7 Nginx: Default version MySQL: MariaDB PHP: Version PHP71 Linux Open required ports after server setup: 80 for HTTP 443 for HTTPS (optional) 3306 for remote MySQL connections Nginx Install Nginx on CentOS: yum install nginx -y Start Nginx: nginx Enable auto-start: systemctl enable nginx Configuration: Default config file: /etc/nginx/nginx.conf Add include /etc/nginx/conf.d/*.conf; to load custom configurations Remove default server block and create new config: vi /etc/nginx/conf.</description></item><item><title>Permission Control via Routing in Laravel (Not Limited to Laravel, Just a Conceptual Approach)</title><link>https://sethix.com/posts/2018032712/</link><pubDate>Tue, 27 Mar 2018 12:53:51 +0800</pubDate><guid>https://sethix.com/posts/2018032712/</guid><description>Start Permission design is a crucial feature for backend management systems. PHP already has many mature packages for this purpose, so we don&amp;rsquo;t need to reinvent the wheel (though you certainly can if preferred).
PS Here are two common historical approaches for permission verification:
Verify required permissions individually on each page Centralized verification via middleware First, let&amp;rsquo;s examine a simplified database schema (retaining only critical fields) with its ER diagram: Database Model Diagram (Note: In this design, users don&amp;rsquo;t directly possess permissions but inherit them through roles.</description></item><item><title>Application of Laravel Model Events</title><link>https://sethix.com/posts/2018031821/</link><pubDate>Sun, 18 Mar 2018 21:02:55 +0800</pubDate><guid>https://sethix.com/posts/2018031821/</guid><description>In daily processing of user operation events, we sometimes need to record them for future reference or big data statistics.
Laravel handles model events conveniently: https://laravel-china.org/docs/laravel/5.5/eloquent#events
There are two approaches to Laravel model events:
Set the dispatchesEvents property to map event classes Use observers to register events (this article focuses on the second approach) Implementation Steps Create Model
php artisan make:model Log &amp;lt;?php namespace App; use Illuminate\Database\Eloquent\Model; class Log extends Model { protected $fillable = [&amp;#39;user_name&amp;#39;, &amp;#39;user_id&amp;#39;, &amp;#39;url&amp;#39;, &amp;#39;event&amp;#39;, &amp;#39;method&amp;#39;, &amp;#39;table&amp;#39;, &amp;#39;description&amp;#39;]; } Create Migration Table</description></item><item><title>One-Click PHP Extension Installer</title><link>https://sethix.com/posts/2018022717/</link><pubDate>Tue, 27 Feb 2018 17:00:02 +0800</pubDate><guid>https://sethix.com/posts/2018022717/</guid><description>When beginners learn PHP through tutorial videos, they often encounter the need to enable extensions like openssl and curl, which can be activated by simply modifying the php.ini file. However, installing extensions like redis and memcache requires finding the correct versions matching their PHP, NTS, VC, and Windows environment - a process that&amp;rsquo;s straightforward for experienced developers but challenging for newcomers.
To solve this problem, we&amp;rsquo;ve developed a one-click PHP extension installer program.</description></item></channel></rss>