What is the limit in size of a Php variable when storing string?

So, is there a limit in size to a Php variable to stores value, in this case, a string ?

Yes. A string can be as large as up to 2GB (2147483647 bytes maximum). You can override this limit by increasing memory_limit directive in php.ini.

From php7 there's not that limitation in a 64 bit system:

Support for strings with length >= 2^31 bytes in 64 bit builds.


The maximum number of bytes a script is allowed to allocate is set in php.ini. Look for memory_limit. This is 16Mb after PHP 5.2.0 as a default!

This can be changed by doing a:

ini_set('memory_limit','24M');

The maximum size of a string is 2 GB in PHP, probably because of adressing limitations, if allowed by memory_limit.