PHP 8.5.2 Released!

gc_collect_cycles

(PHP 5 >= 5.3.0, PHP 7, PHP 8)

gc_collect_cyclesすべての既存ガベージサイクルを強制的に収集する

説明

gc_collect_cycles(): int

すべての既存ガベージサイクルを強制的に収集します。

パラメータ

この関数にはパラメータはありません。

戻り値

収集したサイクルの数を返します。

add a note

User Contributed Notes 2 notes

up
200
Mason
14 years ago
(Since this function wasn't documented as of the date I left this note...)

If you came here looking for documentation, allow me to point you instead to a section in the user manual about garbage collection that includes a bit at the end about when you would use this feature and what it will actually do: http://php.net/manual/en/features.gc.collecting-cycles.php

Hope it helps!
up
0
jab_creations at yahoo dot com
22 hours ago
I haven't properly confirmed though a lot of people are saying PHP doesn't run garbage collection (e.g. clearing out expired session files) on localhost. Also if this has changed I don't know the old/new version cut-off either.

If this is true then you need to first determine if the client (who you should always verify, never trust) has sent the HTTP_HOST request header. If so, there are the three basic values that you'll see unlike on a live server (you'll instead see something like 'www.example.com' or 'example.com'). Don't forget about modifications you've made on your OS's hosts file (or equivalent). Don't forget any relevant networking/router/modem settings too, again, if applicable.

You could append this to your custom local homepage, setup a maintenance page or if you're running a template system append this after the XML/HTML has been sent though you very likely don't want extra stuff running on your live server only intended for your local server unless you do it after flushing the page and continue processing afterwards:

<?php
if (isset($_SERVER['HTTP_HOST']) && in_array($_SERVER['HTTP_HOST'], array('127.0.0.1','::1','localhost'))
{
 gc_collect_cycles();
}
?>
To Top