swoole / swoole-src

🚀 Coroutine-based concurrency library for PHP
https://www.swoole.com
Apache License 2.0
18.47k stars 3.16k forks source link

Swoolew HTTP Server rejects Requests larger than over 2MB #3125

Closed tux-rampage closed 4 years ago

tux-rampage commented 4 years ago

I created a simple setup to measure swooles I/O capacities: https://github.com/tux-rampage/swoole-io-test

During the tests I found out Swoole is always rejecting Requests larger than 2MB with the status code 413.

I guess this is related to #2373 (Which was a case I wanted to test in terms of memory consumption).

  1. What did you do? If possible, provide a simple script for reproducing the error.

    • Sending a request with 1GB of data to a swoole webserver
  2. What did you expect to see?

    • A 204 Response as defined in the handler
  3. What did you see instead?

    • HTTP response 413 Request entity too large
  4. What version of Swoole are you using (show your php --ri swoole)?

swoole

Swoole => enabled
Author => Swoole Team <team@swoole.com>
Version => 4.4.16
Built => Feb 21 2020 09:46:05
coroutine => enabled
epoll => enabled
eventfd => enabled
signalfd => enabled
cpu_affinity => enabled
spinlock => enabled
rwlock => enabled
sockets => enabled
openssl => OpenSSL 1.1.1d  10 Sep 2019
http2 => enabled
pcre => enabled
mutex_timedlock => enabled
pthread_barrier => enabled
futex => enabled
mysqlnd => enabled
async_redis => enabled

Directive => Local Value => Master Value
swoole.enable_coroutine => On => On
swoole.enable_library => On => On
swoole.enable_preemptive_scheduler => Off => Off
swoole.display_errors => On => On
swoole.use_shortname => On => On
swoole.unixsock_buffer_size => 8388608 => 8388608
  1. What is your machine environment used (including version of kernel & php & gcc) ?

    • Ubuntu 18.04
matyhtf commented 4 years ago

You can set the package_max_length option to increase the maximum length limit. But this takes more memory, because Swoole-HTTP-Server keeps all requested data in memory, not disk.

$http = new Swoole\Http\Server("127.0.0.1", 9501);
$http->set([
    'package_max_length' => 16 * 1024 * 1024,
])
Seriosus commented 8 months ago

@matyhtf but increasing body size from php.ini can also do the trick?

Or must be did in the way you provided?

If so, then how to clean the used memory by a file upload?

DanilShapilov commented 7 months ago

For those who using Laravel https://github.com/laravel/octane/issues/442#issuecomment-996013081