Update error: FormatException: SyntaxError: Unexpected end of JSON input ⚠

it depends on your server Operating system.
Is it Windows or Linux?

If Linux then it usually the php is:
/etc/php
If Windows the path usually is:
C:\Program Files\php

If shared hosting environment as mentioned above you may be limited by your hosts server configuration.

Kind regards
AngryWarrior

@hillel @david

I just did an upgrade from v5.5.17 to v5.5.19 on my InvoiceNinja instance taking some quick and dirty memory usage stats. The system is/was:

  • issuing a FormatException: SyntaxError: Unexpected end of JSON input in recent upgrades,
  • had its php memory_limit raised from 256M to 512M and was then freshly rebooted (both just minutes before the upgrade),
  • using php-fpm,
  • serving no other web sites or anything else of significance,
  • performing this upgrade without producing the FormatException.

me@in /home/me> ps -ef | egrep “PID|fpm”
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 605 0.0 0.3 226744 31348 ? Ss 17:59 0:00 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
www-data 801 0.2 0.9 244540 75152 ? S 17:59 0:01 php-fpm: pool www
www-data 802 0.3 0.8 232984 68348 ? S 17:59 0:02 php-fpm: pool www
www-data 1436 0.1 0.6 228068 50464 ? S 18:04 0:00 php-fpm: pool www

During the upgrade output changed to

me@in /home/me> ps -ef | egrep “PID|fpm”
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 605 0.0 0.3 226744 31348 ? Ss 17:59 0:00 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
www-data 801 0.2 0.9 244540 75152 ? S 17:59 0:01 php-fpm: pool www
www-data 802 0.3 0.8 232984 68348 ? S 17:59 0:02 php-fpm: pool www
www-data 1436 3.1 3.4 454040 279676 ? R 18:04 0:11 php-fpm: pool www

Conclusion: Obviously PID 1436 is processing the upgrade. Looking at the RSS (resident set size; that is the unswapped in-core memory used by the process) and VSZ (virtual set size; that is the total virtual memory size of the process, some of which may be unused or in swap) a php memory_limit of 256M is too small to perform an upgrade. In the case of limited memory, php-fpm probably performs garbage collection to free up memory, but given the system had just been rebooted minutes ago I suspect there ain’t much space to be freed up. A php memory_limit of 512M may soon become to small, or may already be too small for sites with significantly larger databases or a longer uptime. Memory usage about one hour after the upgrade (with no usage of the web frontend) looks like

me@in /home/me> ps -ef | egrep “PID|fpm”
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 605 0.0 0.3 226744 31348 ? Ss 17:59 0:00 php-fpm: master process (/etc/php/8.1/fpm/php-fpm.conf)
www-data 801 0.0 0.9 230976 73712 ? S 17:59 0:03 php-fpm: pool www
www-data 802 0.1 0.9 231000 77184 ? S 17:59 0:03 php-fpm: pool www
www-data 1436 0.4 1.2 242380 98208 ? S 18:04 0:14 php-fpm: pool www

So it looks like the minimum php memory_limit should be 512M with a recommendation to go to 1024M.

2 Likes

Thank you @xoo, this is very helpful!

@xoo

Thanks this is helpful, file_get_contents() loads the entire file into memory, hence why we are seeing this issue.

I’m yet to find a reliable way to consistently pull in the file across platforms but i’ll keep trying :slight_smile:

If it helps, this error also used to pop up in Ubuntu 22.04 due to some changes in openssl bundled with it.

It also pops up if fastcgi times out before the update is finished, or the reverse proxy times out before the update is finished. In the cases of timeout the update will continue in the background and complete after a few minutes. Increasing the server or reverse proxy timeouts fixes it.