# Very slow Nextcloud sync ?php-fpm issue [Solved]

## tabanus

Since moving from www-server/lighttpd-1.4.45 to www-server/lighttpd-1.4.45-r1 my Nextcloud server has become very slow, such that the clients time out when trying to sync larger files. Reverting to www-server/lighttpd-1.4.45 hasn't helped.

I'm pretty sure this is a fastcgi issue because I have seen errors in the php-fpm log.

lighttpd and php error logs (the server was rebooted at 17.09 today):

```
cat /var/log/lighttpd/error.log

2018-05-04 03:10:01: (server.c.1534) logfiles cycled UID = 0 PID = 18895 

2018-05-04 10:00:11: (mod_fastcgi.c.2424) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:9000 

2018-05-04 10:00:11: (mod_fastcgi.c.3175) response not received, request sent: 468291 on socket: tcp:127.0.0.1:9000 for /nextcloud/remote.php?, closing connection 

2018-05-04 10:00:18: (mod_fastcgi.c.2424) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:9000 

2018-05-04 10:00:18: (mod_fastcgi.c.3175) response not received, request sent: 471354 on socket: tcp:127.0.0.1:9000 for /nextcloud/remote.php?, closing connection 

2018-05-04 10:00:29: (mod_fastcgi.c.2424) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:9000 

2018-05-04 10:00:29: (mod_fastcgi.c.3175) response not received, request sent: 561167 on socket: tcp:127.0.0.1:9000 for /nextcloud/remote.php?, closing connection 

2018-05-04 10:00:30: (mod_fastcgi.c.2424) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:9000 

2018-05-04 10:00:30: (mod_fastcgi.c.3175) response not received, request sent: 1329 on socket: tcp:127.0.0.1:9000 for /nextcloud/ocs/v2.php?format=json, closing connection 

2018-05-04 10:00:30: (mod_fastcgi.c.2424) unexpected end-of-file (perhaps the fastcgi process died): pid: 0 socket: tcp:127.0.0.1:9000 

2018-05-04 10:00:30: (mod_fastcgi.c.3175) response not received, request sent: 1626 on socket: tcp:127.0.0.1:9000 for /nextcloud/remote.php?, closing connection 

2018-05-04 10:00:37: (mod_fastcgi.c.2723) establishing connection failed: Connection refused socket: tcp:127.0.0.1:9000 

2018-05-04 10:00:37: (mod_fastcgi.c.2729) backend is overloaded; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 1 

2018-05-04 10:00:37: (mod_fastcgi.c.1689) all handlers for /nextcloud/remote.php? on .php are down. 

2018-05-04 10:00:39: (mod_fastcgi.c.2686) fcgi-server re-enabled: tcp:127.0.0.1:9000 

2018-05-04 10:00:43: (mod_fastcgi.c.2723) establishing connection failed: Connection refused socket: tcp:127.0.0.1:9000 

2018-05-04 10:00:43: (mod_fastcgi.c.2729) backend is overloaded; we'll disable it for 1 seconds and send the request to another backend instead: reconnects: 0 load: 1 

2018-05-04 10:00:43: (mod_fastcgi.c.1689) all handlers for /nextcloud/remote.php? on .php are down. 

2018-05-04 10:00:45: (mod_fastcgi.c.2686) fcgi-server re-enabled: tcp:127.0.0.1:9000 

2018-05-04 10:13:30: (server.c.1828) server stopped by UID = 0 PID = 9822 

2018-05-04 10:13:31: (log.c.217) server started 

2018-05-04 10:22:51: (server.c.1828) server stopped by UID = 0 PID = 10123 

2018-05-04 10:22:52: (log.c.217) server started 

2018-05-04 10:22:52: (mod_fastcgi.c.1159) the fastcgi-backend /usr/bin/php-fpm failed to start: 

2018-05-04 10:22:52: (mod_fastcgi.c.1163) child exited with status 78 /usr/bin/php-fpm 

2018-05-04 10:22:52: (mod_fastcgi.c.1166) If you're trying to run your app as a FastCGI backend, make sure you're using the FastCGI-enabled version.\nIf this is PHP on Gentoo, add 'fastcgi' to the USE flags. 

2018-05-04 10:22:52: (mod_fastcgi.c.1518) [ERROR]: spawning fcgi failed. 

2018-05-04 10:22:52: (server.c.1269) Configuration of plugins failed. Going down. 

2018-05-04 10:25:02: (log.c.217) server started 

2018-05-04 17:07:58: (server.c.1828) server stopped by UID = 0 PID = 12636 

2018-05-04 17:07:59: (log.c.217) server started 

2018-05-04 17:09:51: (server.c.1828) server stopped by UID = 0 PID = 12754 

2018-05-04 17:12:45: (log.c.217) server started
```

```
cat /var/log/php-fpm.log | tail

[04-May-2018 10:00:45] NOTICE: configuration file /etc/php/fpm-php7.1/php-fpm.conf test is successful

[04-May-2018 10:00:45] NOTICE: fpm is running, pid 9219

[04-May-2018 10:00:45] NOTICE: ready to handle connections

[04-May-2018 17:09:59] NOTICE: Terminating ...

[04-May-2018 17:10:22] NOTICE: exiting, bye-bye!

[04-May-2018 17:12:51] NOTICE: configuration file /etc/php/fpm-php7.1/php-fpm.conf test is successful

[04-May-2018 17:12:51] NOTICE: fpm is running, pid 2980

[04-May-2018 17:12:51] NOTICE: ready to handle connections
```

No errors in /var/www/localhost/htdocs/nextcloud/data/nextcloud.log

Config files:

```
# cat /etc/lighttpd/mod_fastcgi.conf

###############################################################################

# mod_fastcgi.conf

# include'd by lighttpd.conf.

###############################################################################

server.modules += ("mod_fastcgi")

fastcgi.server = ( ".php" =>

  ( "localhost" =>

    (

      "host" => "127.0.0.1",

      "port" => "9000"

    )

  )

)

```

lighttpd config:

```
# grep  -v ^# /etc/lighttpd/lighttpd.conf | grep -v ^$

var.basedir  = "/var/www/localhost"

var.logdir   = "/var/log/lighttpd"

var.statedir = "/var/lib/lighttpd"

server.modules = (

    "mod_access",

    "mod_accesslog"

)

include "mime-types.conf"

server.username      = "lighttpd"

server.groupname     = "lighttpd"

server.document-root = var.basedir + "/htdocs"

server.pid-file      = "/var/run/lighttpd.pid"

server.errorlog      = var.logdir  + "/error.log"

server.indexfiles    = ("index.php", "index.html",

                                                "index.htm", "default.htm")

server.follow-symlink = "enable"

   server.stat-cache-engine = "fam"

static-file.exclude-extensions = (".php", ".pl", ".cgi", ".fcgi")

accesslog.filename   = var.logdir + "/access.log"

url.access-deny = ("~", ".inc")

$SERVER["socket"] == ":443" {

 ssl.engine    = "enable"

 ssl.pemfile   = "/etc/lighttpd/certs/lighttpd.pem"

}

include "mod_fastcgi.conf"
```

php-fpm config:

```
# grep  -v ^# /etc/php/fpm-php7.1/php-fpm.conf | grep -v ^$                           

;;;;;;;;;;;;;;;;;;;;;

; FPM Configuration ;

;;;;;;;;;;;;;;;;;;;;;

; All relative paths in this configuration file are relative to PHP's install

; prefix (/usr/lib64/php7.1). This prefix can be dynamically changed by using the

; '-p' argument from the command line.

;;;;;;;;;;;;;;;;;;

; Global Options ;

;;;;;;;;;;;;;;;;;;

[global]

; Pid file

; Note: the default prefix is /var

; Default Value: none

;pid = run/php-fpm.pid

; Error log file

; If it's set to "syslog", log is sent to syslogd instead of being written

; into a local file.

; Note: the default prefix is /var

; Default Value: log/php-fpm.log

error_log = /var/log/php-fpm.log

; syslog_facility is used to specify what type of program is logging the

; message. This lets syslogd specify that messages from different facilities

; will be handled differently.

; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)

; Default Value: daemon

;syslog.facility = daemon

; syslog_ident is prepended to every message. If you have multiple FPM

; instances running on the same server, you can change the default value

; which must suit common needs.

; Default Value: php-fpm

;syslog.ident = php-fpm

; Log level

; Possible Values: alert, error, warning, notice, debug

; Default Value: notice

;log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time

; interval set by emergency_restart_interval then FPM will restart. A value

; of '0' means 'Off'.

; Default Value: 0

;emergency_restart_threshold = 0

; Interval of time used by emergency_restart_interval to determine when

; a graceful restart will be initiated.  This can be useful to work around

; accidental corruptions in an accelerator's shared memory.

; Available Units: s(econds), m(inutes), h(ours), or d(ays)

; Default Unit: seconds

; Default Value: 0

;emergency_restart_interval = 0

; Time limit for child processes to wait for a reaction on signals from master.

; Available units: s(econds), m(inutes), h(ours), or d(ays)

; Default Unit: seconds

; Default Value: 0

;process_control_timeout = 0

; The maximum number of processes FPM will fork. This has been designed to control

; the global number of processes when using dynamic PM within a lot of pools.

; Use it with caution.

; Note: A value of 0 indicates no limit

; Default Value: 0

; process.max = 128

; Specify the nice(2) priority to apply to the master process (only if set)

; The value can vary from -19 (highest priority) to 20 (lowest priority)

; Note: - It will only work if the FPM master process is launched as root

;       - The pool process will inherit the master process priority

;         unless specified otherwise

; Default Value: no set

; process.priority = -19

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.

; Default Value: yes

;daemonize = yes

; Set open file descriptor rlimit for the master process.

; Default Value: system defined value

;rlimit_files = 1024

; Set max core size rlimit for the master process.

; Possible Values: 'unlimited' or an integer greater or equal to 0

; Default Value: system defined value

;rlimit_core = 0

; Specify the event mechanism FPM will use. The following is available:

; - select     (any POSIX os)

; - poll       (any POSIX os)

; - epoll      (linux >= 2.5.44)

; - kqueue     (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)

; - /dev/poll  (Solaris >= 7)

; - port       (Solaris >= 10)

; Default Value: not set (auto detection)

;events.mechanism = epoll

; When FPM is built with systemd integration, specify the interval,

; in seconds, between health report notification to systemd.

; Set to 0 to disable.

; Available Units: s(econds), m(inutes), h(ours)

; Default Unit: seconds

; Default value: 10

;systemd_interval = 10

;;;;;;;;;;;;;;;;;;;;

; Pool Definitions ;

;;;;;;;;;;;;;;;;;;;;

; Multiple pools of child processes may be started with different listening

; ports and different management options.  The name of the pool will be

; used in logs and stats. There is no limitation on the number of pools which

; FPM can handle. Your system will tell you anyway :)

; Include one or more files. If glob(3) exists, it is used to include a bunch of

; files from a glob(3) pattern. This directive can be used everywhere in the

; file.

; Relative path can also be used. They will be prefixed by:

;  - the global prefix if it's been set (-p argument)

;  - /usr/lib64/php7.1 otherwise

include=/etc/php/fpm-php7.1/fpm.d/*.conf

user = lighttpd

group = lighttpd

env[HOSTNAME] = $HOSTNAME

env[PATH] = /usr/local/bin:/usr/bin:/bin:/var/www/localhost/htdocs:

env[TMP] = /tmp

;[php-fpm-pool-settings]  

pm = dynamic  

pm.max_children = 25  

pm.start_servers = 10  

pm.min_spare_servers = 5  

pm.max_spare_servers = 20  

pm.max_requests = 498

```

Thanks

----------

## tabanus

Actually this looks like a hardware problem https://forums.gentoo.org/viewtopic-t-1080854.html

----------

