{"id":11423,"date":"2019-01-09T09:44:38","date_gmt":"2019-01-09T08:44:38","guid":{"rendered":"http:\/\/www.wjst.de\/blog\/?p=11423"},"modified":"2019-01-09T13:11:50","modified_gmt":"2019-01-09T12:11:50","slug":"php-segmentation-error-11","status":"publish","type":"post","link":"https:\/\/www.wjst.de\/blog\/sciencesurf\/2019\/01\/php-segmentation-error-11\/","title":{"rendered":"PHP Segmentation Error 11"},"content":{"rendered":"<p>Just a few days before public deployment of my new website this error popped up in the terminal. Apache was running fine but my favorite php test server crashed after 5 minutes.<!--more--><\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nsudo php -S 0.0.0.0:80 -t \/Users\/wjst\/Server\r\n<\/pre>\n<p>Unfortunately, error logging did not help, at least not the usual way<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nini_set('display_errors', 1);\r\nini_set('display_startup_errors', 1);\r\nerror_reporting(E_ALL);\r\n<\/pre>\n<p>I could see only the last retrieved page in the terminal but adding<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nfile_put_contents('debug.log', print_r(get_defined_vars(),1));\r\n<\/pre>\n<p>did not show any error log. Also encapsulating<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\ntry {\r\n}\r\ncatch(PDOException $e) {\r\n  #echo $e-&gt;getMessage();\r\n}\r\n<\/pre>\n<p>was not successful. So I updated PHP <a href=\"https:\/\/php-osx.liip.ch\">which is always a good idea<\/a>.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\ncurl -s https:\/\/php-osx.liip.ch\/install.sh | bash -s 7.2\r\n<\/pre>\n<p>while the error remained. And no logs even after running<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nphp -d xdebug.auto_trace=ON -d xdebug.trace_output_dir=tracedir\/\r\n<\/pre>\n<p>Unfortunately, there is no strace on OSX so I tried <a href=\"https:\/\/8thlight.com\/blog\/colin-jones\/2015\/11\/06\/dtrace-even-better-than-strace-for-osx.html\">dtrace<\/a> but have been giving up this strategy after 2 hours as the output was not readable at all. <a href=\"https:\/\/entwickler.de\/online\/web\/segmentation-faults-der-schlimmste-aller-fehler-ist-132888.html\">Segmentation errors are a nightmare<\/a>.<\/p>\n<p>Going the hard way &#8211; uncommenting each line step by step &#8211; it turned out that the sqlite database query killed the server. Looping over different SQL statements did not replicate the error, which occured only when the script was invoked by AJAX calls. So I removed all variables relying on the $_SERVER environment but again, the segmentation error persisted. Strange.<\/p>\n<p>Finally I found the problem. Whenever a query<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n$db = new PDO('sqlite:database.sqlite3');\r\n$result = $db-&gt;query($sql);\r\n<\/pre>\n<p>was leading to an empty result set, the segmentation error occurred.<\/p>\n<p>As this occurs <span style=\"text-decoration: underline;\">during<\/span> execution of the query, the only workaround was to ensure that there is always at least one result set.<\/p>\n<p>Sounds not very logical but this worked out now for the last 24 hours.<\/p>\n\n<p>&nbsp;<\/p>\n<div class=\"bottom-note\">\n  <span class=\"mod1\">CC-BY-NC Science Surf , accessed 12.04.2026<\/span>\n <\/div>","protected":false},"excerpt":{"rendered":"<p>Just a few days before public deployment of my new website this error popped up in the terminal. Apache was running fine but my favorite php test server crashed after 5 minutes. &nbsp; CC-BY-NC Science Surf , accessed 12.04.2026<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-11423","post","type-post","status-publish","format-standard","hentry","category-computer-software"],"_links":{"self":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/11423","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/comments?post=11423"}],"version-history":[{"count":12,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/11423\/revisions"}],"predecessor-version":[{"id":11435,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/posts\/11423\/revisions\/11435"}],"wp:attachment":[{"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/media?parent=11423"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/categories?post=11423"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wjst.de\/blog\/wp-json\/wp\/v2\/tags?post=11423"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}