phpvitelaragon

PHP through Laragon giving "Warning: Failed to set memory limit to 1024 bytes (Current memory usage is 2097152 bytes) in Unknown on line 0" error


Recently I tried to increase the memory_limit available to PHP while using Laragon v5.0 and PHP v8.1.4.

In Laragon, I went to Menu -> PHP -> Quick settings -> memory_limit, and entered "1024", thinking this was in MB.

Subsequently, running PHP scripts gives an error in the console that reads Warning: Failed to set memory limit to 1024 bytes (Current memory usage is 2097152 bytes) in Unknown on line 0. This causes Vite to crash when attempting to run a build or dev server, as this message is passed to the Laravel inertia/Vite connector. That was throwing this error:

error during build:
Error: [vite:laravel:config] Could not read configuration: Unexpected token W in JSON at position 1

Laragon doesn't present a way of undoing this memory_limit setting, and making changes to the number weren't having any effect.


Solution

  • I eventually had luck navigating to php.ini and commenting out the memory limit change.

    This can be accessed through Laragon through Menu -> PHP -> php.ini, or if this doesn't work, Menu -> PHP -> dir:ext, then going up one level in File Explorer and opening the php.ini file in a text editor from there. In my case, the file is at: C:\laragon\bin\php\php-8.1.4-Win32-vs16-x64\php.ini

    Then, I found these lines:

    ; Maximum amount of memory a script may consume
    ; https://php.net/memory-limit
    memory_limit = 1024
    

    And changed them to

    ; Maximum amount of memory a script may consume
    ; https://php.net/memory-limit
    ; memory_limit = 1024
    

    PHP scripts now runs without errors or warnings.