Site Health : An active PHP session was detected

I’m new in WordPress development and I just created my first theme.

In my wp-admin, the "Site Health" tells me that a PHP session has been detected (critical error), here is the message :

A PHP session was created by a session_start() function call. This
interferes with REST API and loopback requests. The session should be
closed by session_write_close() before making any HTTP requests.

I need PHP’s $_SESSION for a theme script, and I added this to my functions.php file for sessions to be properly initialized:

If I delete these lines, the message disappears, but my PHP sessions don’t work anymore.

If I keep these lines, everything seems to be working properly but this message is worrying…

Does anyone have an idea to solve this problem while keeping the ability to use the $_SESSION?

My WP version is 5.5.3 and the PHP version is 7.4.8.

Thank you in advance for your help!

Xin chào các bạn và quý Thầy Cô. Hãy nhập từ khóa mình muốn vào ô tìm kiếm trên Website để tìm kiếm mọi thứ hoặc trên google các bạn hãy nhập từ khóa + dethihsg247.com để tìm kiếm các bài viết của chúng tôi nhé.
  • Hiện tại chúng tôi có hơn 25 nghìn bài văn mẫu các thể loại.
  • Kho tài liệu, đề thi học sinh giỏi các lớp vô cùng phong phú.
  • Mỗi ngày cập nhật hơn 100 đề thi chất lượng từ các website bán tài liệu lớn.

Tải đề thi VIP với giá siêu rẻ tại Vip.Dethihsg247.Com