HTTP client extension based on Yii 2, upload files, php fatal errorYii\Base\ErrorExceptionwith messageAllowed memory size of 2147483648 bytes exhausted (Tried to allocate 1084897244 bytes)analysis solution
1. PHP fatal errorYii\Base\ErrorExceptionwith messageAllowed memory size of 2147483648 bytes exhausted (Tried to allocate 1084897244 bytes). as shown in Figure 1
The command "'/usr/local/php/bin/php' '/mcloud/www/channel-pub-api/yii' 'upload-asset-queue/exec' '45' '7200' '1' '1010' '--verbose=1' '--color=0'" failed.
Exit Code: 255(Unknown error)
Working directory: /
Output:
================
2020-12-04 14:31:27 [45] common\jobs\UploadAssetJob (attempt: 1, pid: 1010) - Started
Error Output:
================
PHP Fatal Error 'yii\base\ErrorException' with message 'Allowed memory size of 2147483648 bytes exhausted (tried to allocate 1084897244 bytes)'
in /mcloud/www/channel-pub-api/vendor/yiisoft/yii2-httpclient/src/Request.php:381
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}
2. Downloaded files:https://webtv-test.oss-cn-beijing.aliyuncs.com/rmhadmin/vod/2020/12/02/b73b9e8c3796447494a9dbe6dc66e2ad/b73b9e8c3796447494a9dbe6dc66e2ad_h264_1200k_mp4.mp4. Its size is 1.44 GB. In the local environment, this file is successfully downloaded, memory usage: 6.376 MB, time consuming: 916,308 ms. as shown in Figure 2
3, the uploaded file, its size is 50.5 MB. In the local environment, this file is uploaded successfully, and the memory usage is 164.813 MB, which takes time: 43,244 ms. The uploaded file is 117 MB in size. In the local environment, this file is successfully uploaded, and the memory usage is 362.813 MB, which takes time: 97,774 ms. It can be concluded that the memory usage is about 3 times the size of the file. Figure 3, Figure 4
4. The memory usage is optimized, and there is no better solution. Therefore, finally by modifying the configuration options of the resource limit of php.ini . memory_limit = 4096M. Sets the maximum amount of memory to be allocated by a script. The uploaded file is 1.01 GB in size. No errors were reported again.
5. But when the file size of the upload is 1.44 GB, the error is still reported. memory_limit = 6144M. No errors were reported again.
The command "'/usr/local/php/bin/php' '/mcloud/www/channel-pub-api/yii' 'upload-asset-queue/exec' '68' '7200' '1' '1012' '--verbose=1' '--color=0'" failed.
Exit Code: 255(Unknown error)
Working directory: /
Output:
================
2020-12-07 17:54:21 [68] common\jobs\UploadAssetJob (attempt: 1, pid: 1012) - Started
Error Output:
================
PHP Fatal Error 'yii\base\ErrorException' with message 'Allowed memory size of 4294967296 bytes exhausted (tried to allocate 1551797080 bytes)'
in /mcloud/www/channel-pub-api/vendor/yiisoft/yii2-httpclient/src/Request.php:391
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleFatalError()
#1 {main}



