I have a script that I saved in /etc/init.d/my_service following content

 #!/bin/sh sudo -u www-data php -f /var/www/my_service.php > /var/log/my_service.log 2>&1 & 

I run the PHP script as a daemon on behalf of the user www-data and save all output to the log file

PHP script has a general view (using symfony and Doctrine)

 <?php while (true) { // получаем запись из БД $entity = $this->repository->findEntity(); if ($entity) { $this->handler->handleEntity($entity); // что-то делаем $this->em->flush(); // сохраняем изменение в бд // бросаем событие об успешном выполнении действия $this->dispatcher->dispatch(StoreEvents::UPDATE_ENTITY, new UpdateEntity($entity)); } $sleep = rand(10, 800); echo "sleep $sleep s.\n"; sleep($sleep); // засыпаем unset($entity); // удаляем неиспользуемый объект gc_collect_cycles(); // garbage collection } 

so here The problem is that the script runs for several days and then freezes. In the logs, I see that his last action was sleep 10 s. . The actions that this script should perform, it does not perform, but it also works. Did not fall.

 $ ps aux | grep my_service | grep -v grep root 14517 0.0 0.1 54092 3856 ? S июн17 0:00 sudo -u www-data php -f /var/www/my_service.php www-data 14518 0.1 7.4 496776 151844 ? S июн17 5:15 php -f /var/www/my_service.php 

In error logs is empty. I do not observe memory leakage behind the script. For 4 days, the script ate 7.4% of memory (this is within the normal range). But the muscle ate 47%, but there are several gigs in the base, so it’s also the norm. There is space on the disk. Memory is still there.

In general, the question. What am I doing wrong and where to dig? A question more likely to diagnose the error.

 $ lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 16.04 LTS Release: 16.04 Codename: xenial $ uname -r 4.4.0-22-generic $ php -v PHP 7.0.4-7ubuntu2.1 (cli) ( NTS ) Copyright (c) 1997-2016 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies $ mysql -V mysql Ver 14.14 Distrib 5.7.12, for Linux (x86_64) using EditLine wrapper 

PS: Reject PHP is not possible due to the complex business logic tied to the site.

The output from gdb. Maybe it will tell someone something.

 $ gdb -pid=14518 (gdb) bt #0 0x00007f7dd8bb8d13 in select () at ../sysdeps/unix/syscall-template.S:84 #1 0x00007f7dd4920f59 in zif_curl_multi_select () from /usr/lib/php/20151012/curl.so #2 0x000055d4b6f138aa in dtrace_execute_internal () #3 0x000055d4b6fa7320 in ?? () #4 0x000055d4b6f6316b in execute_ex () #5 0x000055d4b6f13741 in dtrace_execute_ex () #6 0x000055d4b6fa745d in ?? () #7 0x000055d4b6f6316b in execute_ex () #8 0x000055d4b6f13741 in dtrace_execute_ex () #9 0x000055d4b6fa745d in ?? () #10 0x000055d4b6f6316b in execute_ex () #11 0x000055d4b6f13741 in dtrace_execute_ex () #12 0x000055d4b6fa745d in ?? () #13 0x000055d4b6f6316b in execute_ex () #14 0x000055d4b6f13741 in dtrace_execute_ex () #15 0x000055d4b6fa745d in ?? () #16 0x000055d4b6f6316b in execute_ex () #17 0x000055d4b6f13741 in dtrace_execute_ex () #18 0x000055d4b6fa745d in ?? () #19 0x000055d4b6f6316b in execute_ex () #20 0x000055d4b6f13741 in dtrace_execute_ex () #21 0x000055d4b6fa745d in ?? () #22 0x000055d4b6f6316b in execute_ex () #23 0x000055d4b6f13741 in dtrace_execute_ex () #24 0x000055d4b6fa745d in ?? () #25 0x000055d4b6f6316b in execute_ex () #26 0x000055d4b6f13741 in dtrace_execute_ex () #27 0x000055d4b6fa745d in ?? () #28 0x000055d4b6f6316b in execute_ex () #29 0x000055d4b6f13741 in dtrace_execute_ex () #30 0x000055d4b6fa745d in ?? () #31 0x000055d4b6f6316b in execute_ex () #32 0x000055d4b6f13741 in dtrace_execute_ex () #33 0x000055d4b6fa745d in ?? () #34 0x000055d4b6f6316b in execute_ex () #35 0x000055d4b6f13741 in dtrace_execute_ex () #36 0x000055d4b6fa745d in ?? () #37 0x000055d4b6f6316b in execute_ex () #38 0x000055d4b6f13741 in dtrace_execute_ex () #39 0x000055d4b6fa745d in ?? () #40 0x000055d4b6f6316b in execute_ex () #41 0x000055d4b6f13741 in dtrace_execute_ex () #42 0x000055d4b6fa745d in ?? () #43 0x000055d4b6f6316b in execute_ex () #44 0x000055d4b6f13741 in dtrace_execute_ex () #45 0x000055d4b6fa745d in ?? () #46 0x000055d4b6f6316b in execute_ex () #47 0x000055d4b6f13741 in dtrace_execute_ex () #48 0x000055d4b6fb5fd7 in zend_execute () #49 0x000055d4b6f23993 in zend_execute_scripts () #50 0x000055d4b6ec44e0 in php_execute_script () #51 0x000055d4b6fb7ca4 in ?? () #52 0x000055d4b6da9d54 in main () 

some more debugging pins

 # ps -flp 14518 FS UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD 4 S www-data 14518 14517 0 80 0 - 124194 poll_s июн17 ? 00:05:21 php /var/www/my_service.php # cat /proc/14518/wchan poll_schedule_timeout # cat /proc/14518/status Name: php State: S (sleeping) Tgid: 14518 Ngid: 0 Pid: 14518 PPid: 14517 TracerPid: 0 Uid: 33 33 33 33 Gid: 33 33 33 33 FDSize: 64 Groups: 33 NStgid: 14518 NSpid: 14518 NSpgid: 14511 NSsid: 14410 VmPeak: 496776 kB VmSize: 496776 kB VmLck: 0 kB VmPin: 0 kB VmHWM: 153076 kB VmRSS: 143508 kB VmData: 202320 kB VmStk: 136 kB VmExe: 3744 kB VmLib: 60980 kB VmPTE: 776 kB VmPMD: 16 kB VmSwap: 0 kB HugetlbPages: 0 kB Threads: 1 SigQ: 0/7851 SigPnd: 0000000000000000 ShdPnd: 0000000000000000 SigBlk: 0000000000000000 SigIgn: 0000000000001006 SigCgt: 0000000184000000 CapInh: 0000000000000000 CapPrm: 0000000000000000 CapEff: 0000000000000000 CapBnd: 0000003fffffffff CapAmb: 0000000000000000 Seccomp: 0 Cpus_allowed: 1 Cpus_allowed_list: 0 Mems_allowed: 00000000,00000001 Mems_allowed_list: 0 voluntary_ctxt_switches: 277710 nonvoluntary_ctxt_switches: 45436 # cat /proc/14518/sched php (14518, #threads: 1) ------------------------------------------------------------------- se.exec_start : 1019977529.238328 se.vruntime : 4031586.862977 se.sum_exec_runtime : 321340.158466 se.statistics.sum_sleep_runtime : 346194990.429695 se.statistics.wait_start : 0.000000 se.statistics.sleep_start : 1019977529.238328 se.statistics.block_start : 0.000000 se.statistics.sleep_max : 882000.078842 se.statistics.block_max : 3.172846 se.statistics.exec_max : 12.163842 se.statistics.slice_max : 55.799938 se.statistics.wait_max : 8.977077 se.statistics.wait_sum : 13045.256734 se.statistics.wait_count : 323374 se.statistics.iowait_sum : 77.360204 se.statistics.iowait_count : 138 se.nr_migrations : 0 se.statistics.nr_migrations_cold : 0 se.statistics.nr_failed_migrations_affine : 0 se.statistics.nr_failed_migrations_running : 0 se.statistics.nr_failed_migrations_hot : 0 se.statistics.nr_forced_migrations : 0 se.statistics.nr_wakeups : 277937 se.statistics.nr_wakeups_sync : 38357 se.statistics.nr_wakeups_migrate : 0 se.statistics.nr_wakeups_local : 277937 se.statistics.nr_wakeups_remote : 0 se.statistics.nr_wakeups_affine : 0 se.statistics.nr_wakeups_affine_attempts : 0 se.statistics.nr_wakeups_passive : 0 se.statistics.nr_wakeups_idle : 0 avg_atom : 0.993710 avg_per_cpu : 0.000001 nr_switches : 323374 nr_voluntary_switches : 277938 nr_involuntary_switches : 45436 se.load.weight : 1024 se.avg.load_sum : 88064 se.avg.util_sum : 88064 se.avg.load_avg : 0 se.avg.util_avg : 0 se.avg.last_update_time : 1019977529238328 policy : 0 prio : 120 clock-delta : 153 mm->numa_scan_seq : 0 numa_pages_migrated : 0 numa_preferred_nid : -1 total_numa_faults : 0 current_node=0, numa_group_id=0 numa_faults node=0 task_private=0 task_shared=0 group_private=0 group_shared=0 # cat /proc/14518/schedstat 321346945436 13045546406 323441 # cat /proc/14518/syscall 23 0xe 0x7ffcf3aa6110 0x7ffcf3aa6190 0x7ffcf3aa6210 0x7ffcf3aa6100 0x0 0x7ffcf3aa60d0 0x7f7dd8bb8d13 # cat /proc/14518/stack [<ffffffff81220dc4>] poll_schedule_timeout+0x44/0x70 [<ffffffff812218b7>] do_select+0x727/0x810 [<ffffffff81221b6f>] core_sys_select+0x1cf/0x2f0 [<ffffffff81221d4a>] SyS_select+0xba/0x110 [<ffffffff818252f2>] entry_SYSCALL_64_fastpath+0x16/0x71 [<ffffffffffffffff>] 0xffffffffffffffff 

fd

 # ls -la /proc/14518/fd total 0 dr-x------ 2 www-data www-data 0 Jun 21 15:31 . dr-xr-xr-x 9 www-data www-data 0 Jun 17 16:41 .. lr-x------ 1 www-data www-data 64 Jun 21 15:31 0 -> /dev/null l-wx------ 1 www-data www-data 64 Jun 21 15:31 1 -> /var/www/my_service.log lrwx------ 1 www-data www-data 64 Jun 21 15:31 10 -> socket:[276448] # <====== прокси для php lrwx------ 1 www-data www-data 64 Jun 21 15:31 11 -> socket:[275207] # <====== прокси для php l-wx------ 1 www-data www-data 64 Jun 21 15:31 12 -> /var/www/my_service/failed_load.log # <====== дополнительный внутренний лог lrwx------ 1 www-data www-data 64 Jun 21 15:31 13 -> socket:[276877] # <====== прокси для php l-wx------ 1 www-data www-data 64 Jun 21 15:31 2 -> /var/www/my_service.log lr-x------ 1 www-data www-data 64 Jun 21 15:31 3 -> /dev/urandom l-wx------ 1 www-data www-data 64 Jun 21 15:31 4 -> /var/www/my_service.log l-wx------ 1 www-data www-data 64 Jun 21 15:31 5 -> /var/www/my_service.log lrwx------ 1 www-data www-data 64 Jun 21 15:31 6 -> socket:[245767] # <====== дескриптор не найден l-wx------ 1 www-data www-data 64 Jun 21 15:31 7 -> /var/www/my_service/dev.log # <====== дополнительный внутренний лог lrwx------ 1 www-data www-data 64 Jun 21 15:31 8 -> socket:[276838] # <====== прокси для php lrwx------ 1 www-data www-data 64 Jun 21 15:31 9 -> socket:[245781] # <====== прокси для php 

wrong. last action was not sleep (found in another log)

 [2016-06-19 00:10:33] app.DEBUG: Sleep: 141 s. [] [] [2016-06-19 00:12:54] doctrine.DEBUG: SELECT ... 

the last entry from the log to which the entire output of the program is recorded > /var/log/my_service.log 2>&1

 [2016-06-19 00:10:33] app.DEBUG: Sleep: 141 s. 

gdb

 # gdb /proc/14518/exe GNU gdb (Ubuntu 7.11-0ubuntu1) 7.11 Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". Type "show configuration" for configuration details. For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. Find the GDB manual and other documentation resources online at: <http://www.gnu.org/software/gdb/documentation/>. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /proc/14518/exe...(no debugging symbols found)...done. (gdb) attach 14518 Attaching to program: /proc/14518/exe, process 14518 Reading symbols from /lib/x86_64-linux-gnu/libresolv.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libresolv-2.23.so...done. done. Reading symbols from /lib/x86_64-linux-gnu/libz.so.1...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libpcre.so.3...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libm.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libm-2.23.so...done. done. Reading symbols from /lib/x86_64-linux-gnu/libdl.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libdl-2.23.so...done. done. Reading symbols from /usr/lib/x86_64-linux-gnu/libxml2.so.2...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libssl.so.1.0.0...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libcrypto.so.1.0.0...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libc.so.6...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libc-2.23.so...done. done. Reading symbols from /lib/x86_64-linux-gnu/libpthread.so.0...Reading symbols from /usr/lib/debug/.build-id/b7/7847cc9cacbca3b5753d0d25a32e5795afe75b.debug...done. done. [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Reading symbols from /lib64/ld-linux-x86-64.so.2...warning: the debug information found in "/lib64/ld-2.23.so" does not match "/lib64/ld-linux-x86-64.so.2" (CRC mismatch). Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/ld-2.23.so...done. done. Reading symbols from /usr/lib/x86_64-linux-gnu/libicuuc.so.55...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/liblzma.so.5...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libicudata.so.55...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libstdc++.so.6...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libgcc_s.so.1...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/opcache.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/mysqlnd.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/pdo.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/xml.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/apcu.so...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/librt.so.1...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/librt-2.23.so...done. done. Reading symbols from /usr/lib/php/20151012/calendar.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/ctype.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/curl.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libcurl.so.4...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libidn.so.11...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/librtmp.so.1...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libgssapi_krb5.so.2...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/liblber-2.4.so.2...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libldap_r-2.4.so.2...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libgnutls.so.30...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libhogweed.so.4...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libnettle.so.6...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libgmp.so.10...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libkrb5.so.3...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libk5crypto.so.3...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libcom_err.so.2...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libkrb5support.so.0...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libsasl2.so.2...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libgssapi.so.3...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libp11-kit.so.0...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libtasn1.so.6...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libkeyutils.so.1...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libheimntlm.so.0...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libkrb5.so.26...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libasn1.so.8...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libhcrypto.so.4...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libroken.so.18...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libffi.so.6...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libwind.so.0...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libheimbase.so.1...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libhx509.so.5...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libsqlite3.so.0...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libcrypt.so.1...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libcrypt-2.23.so...done. done. Reading symbols from /usr/lib/php/20151012/dom.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/exif.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/fileinfo.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/ftp.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/gd.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libgd.so.3...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libXpm.so.4...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libjpeg.so.8...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libpng12.so.0...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libfreetype.so.6...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libfontconfig.so.1...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libvpx.so.3...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libtiff.so.5...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libX11.so.6...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libexpat.so.1...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libjbig.so.0...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libxcb.so.1...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libXau.so.6...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libXdmcp.so.6...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/gettext.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/iconv.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/intl.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libicui18n.so.55...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libicuio.so.55...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/json.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/memcached.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libmemcached.so.11...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/mysqli.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/pdo_mysql.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/phar.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/posix.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/readline.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libedit.so.2...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libtinfo.so.5...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libbsd.so.0...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/shmop.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/simplexml.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/sockets.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/sysvmsg.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/sysvsem.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/sysvshm.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/tidy.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/libtidy-0.99.so.0...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/tokenizer.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/wddx.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/xmlreader.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/xmlwriter.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/php/20151012/xsl.so...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libexslt.so.0...(no debugging symbols found)...done. Reading symbols from /usr/lib/x86_64-linux-gnu/libxslt.so.1...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libgcrypt.so.20...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libgpg-error.so.0...(no debugging symbols found)...done. Reading symbols from /lib/x86_64-linux-gnu/libnss_files.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libnss_files-2.23.so...done. done. Reading symbols from /lib/x86_64-linux-gnu/libnss_dns.so.2...Reading symbols from /usr/lib/debug//lib/x86_64-linux-gnu/libnss_dns-2.23.so...done. done. Reading symbols from /usr/lib/x86_64-linux-gnu/gconv/ISO8859-1.so...Reading symbols from /usr/lib/debug//usr/lib/x86_64-linux-gnu/gconv/ISO8859-1.so...done. done. 0x00007f7dd8bb8d13 in select () at ../sysdeps/unix/syscall-template.S:84 84 ../sysdeps/unix/syscall-template.S: No such file or directory. (gdb) 

All file descriptors for socket socket:[xxx] except 245767 served as proxies for curl requests from php. descriptor 245767 not found

 # netstat -apeen | grep 245767 

perhaps on the descriptor 245767 there was a muscle. it fell off somehow, but the script could not react to it. I see only this message in the log, but it was 5 hours after the script was stopped.

 2016-06-19T05:12:54.819918Z 179 [Note] Aborted connection 179 to db: 'database' user: 'user' host: 'localhost' (Got timeout reading communication packets) 

Kurla version

 # curl -V curl 7.47.0 (x86_64-pc-linux-gnu) libcurl/7.47.0 GnuTLS/3.4.10 zlib/1.2.8 libidn/1.32 librtmp/2.3 Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtmp rtsp smb smbs smtp smtps telnet tftp Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz TLS-SRP UnixSockets 

the demon has died

 [2016-06-19 00:10:33] app.DEBUG: Sleep: 141 s. [2016-06-21 23:38:12] php.DEBUG: PDO::beginTransaction(): send of 22 bytes failed with errno=32 Broken pipe {"type":8,"file":"/var/www/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":1176,"level":28928} [Symfony\Component\Debug\Exception\ContextErrorException] Warning: Error while sending QUERY packet. PID=14518 
  • Comments are not intended for extended discussion; conversation moved to chat . - Nick Volynkin
  • I would not put it in /etc/init.d/ since it will start and hang for any action with services and at a stop too. make a unit for sistemd or upstart better - a couple of lines of config, but you can manage it normally. if all the systems-V then start-stop-deamon coolest thing - eri
  • made a fork of the process and in the child already performed all the necessary actions. normal flight. the truth is a new problem. at some stage of the work, the doctrine began to throw exceptions, because it was not possible to write data to the database, and in this case the child process hung and did not die itself. but this problem is already from another series - ghost404

2 answers 2

Run the script via cron, for example, every two minutes, perform the required number of iterations and exit.

PS This is not a demon. Demon - listens, creates connections, etc. He is angry and multi-threaded. You just have a script that every 10 seconds has to process a packet of data from the database. Do not over complicate.

unset($entity); // удаляем неиспользуемый объект unset($entity); // удаляем неиспользуемый объект why unset, if it will be overwritten in the next iteration?

If you want to write an article on Habr how to debug PHP / Symphony / Doctrine - now you are on the right track. I can advise you on tools like http://kcachegrind.sourceforge.net/html/Home.html for profiling PHP dumps. Since a dump for several days will take too much space, you can write a script that checks the responsiveness of the server, if the server responds, the script resets all dumps older than five minutes. if it does not respond, the script terminates the dump process.

As a result, you can see all function calls five minutes before the server hangs. To speed up the process, you can reduce the timeout in the script to one second - when running on a test server.

If you want to perform a business task - do not over-complicate. Use CZK.

  • "crutch support" - etki
  • one
    This is not a crutch but quite standard practice in large offices. php has only recently begun to be used in the form of long-lived processes. if you need to run the script to work correctly, you will not debug a million php libraries and extensions, you simply eliminate the possibility of memory leaks, etc. Moreover, it is not a demon, but simply a script in the iteration. - strangeqargo
  • In bad big offices. In the form of long-lived processes, it is far from the first year that they are launched, and it is not always possible to launch in one-off format. Well and it is possible to close eyes to problems of a code, but it is not necessary. - etki
  • in the good big offices of heavy demons they write in other languages, and this code, in any case, is quite a candidate for the usual launch via cron. - strangeqargo
  • one
    @ ghost404 doesn't matter to you whether it is random or not, it starts up, checks conditions / random, performs a task or iterates, dies with guarantee. Runs again. In any case, good luck to you. - strangeqargo

It’s safer to use bash wrapper.

 #!/bin/bash while true; do /usr/local/bin/php -f /var/www/my_service.php sleep 60 done; 

So exactly resources will be freed after each run of the script.