2

I can't figure out why my nginx is crashing each time I try to use curl:

Code snippet to reproduce a crash:

$request = new \Buzz\Message\Request('GET', '/', 'https://google.com');
$response = new \Buzz\Message\Response();
$client = new \Buzz\Client\Curl();
$client->send($request, $response);

application log

2015/12/29 11:42:30 [error] 213#0: *416 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: dev-fr.local.xxxx.com, request: "GET /login/check-vkontakte?code=xxxxx HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "dev-ru.local.xxxx.com", referrer: "https://dev-ru.local.xxxx.com/"

/var/log/system.log

Dec 29 11:40:54 Alains-MacBook-Pro.local ReportCrash[75875]: Saved crash report for php-fpm[75864] version 0 to /Users/alain/Library/Logs/DiagnosticReports/php-fpm_2015-12-29-114054_Alains-MacBook-Pro.crash

crash report (beginning)

Process:               php-fpm [75865]
Path:                  /usr/local/Cellar/php56/5.6.15/sbin/php-fpm
Identifier:            php-fpm
Version:               0
Code Type:             X86-64 (Native)
Parent Process:        php-fpm [75858]
Responsible:           php-fpm [75858]
User ID:               501

Date/Time:             2015-12-29 11:42:30.733 +0100
OS Version:            Mac OS X 10.10.5 (14F1021)
Report Version:        11
Anonymous UUID:        1DC6CEB0-0479-4A5E-FFD2-E48BA3961196

Sleep/Wake UUID:       A704AF01-8AE8-44D2-BBF3-DED65D834B0B

Time Awake Since Boot: 29000 seconds
Time Since Wake:       3000 seconds

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_BAD_ACCESS (SIGSEGV)
Exception Codes:       KERN_INVALID_ADDRESS at 0x0000000000000110

I searched for hours and always given up, but now I'm tired and really want to fix it.

Complete crash report: http://ninsuo.com/crash-nginx-xxxx.html

My phpinfo(): http://ninsuo.com/phpinfo-xxxx.html

Alain Tiemblo
  • 36,099
  • 17
  • 121
  • 153
  • 2
    The error at [this](https://stackoverflow.com/questions/29570167/swift-1-2-segmentation-fault-on-compile-of-release-scheme) stackoverflow question also ends with `libdyld.dylib start + 1`, they suggest that updating to Xcode 6.3.1 solves the problem, can you try that? – Ferrybig Jan 21 '16 at 13:39
  • On your place I would try writing raw php script for curl, then try doing the same using php command line and if everything fails perhaps `try / catch` + `@` to mute exceptions / fatal errors or register custom error handler. I wouldn't be surprised if you were receiving fatal errors which the server was displaying as Bad Gateway. Of course this is not a proper solution, it's just for debugging. You might also consider using docker or vagrant instead of raw Mac Os X as my friend had quite a lot of issues with segmentation faults on Mac. – Marcin Szulc Jan 21 '16 at 22:59
  • After downgrading Xcode to 6.3.1 and recompiling php56, still no luck. – Alain Tiemblo Jan 22 '16 at 15:16

2 Answers2

3

I experienced same problem early and fixed it with running php-fpm as root. Also I found links which confirms this solution:First link, Second link. Hope it will help you too.

toohtik
  • 1,892
  • 11
  • 27
  • You just killed me. Running php-fpm as root just works well! Thanks!! – Alain Tiemblo Jan 22 '16 at 16:56
  • Glad to hear :) Not sure, bounty award will be assigned later? – toohtik Jan 22 '16 at 17:18
  • Yeah, there are like 48h to be able to throw it :) this should be done now, enjoy & thanks again for sharing! – Alain Tiemblo Jan 22 '16 at 21:53
  • @AlainTiemblo, lol, it may be a solution, but fwiiw, running php as root is certainly not a very good idea at all! OP, may I suggest you keep the bounty open to see if there's a better solution? You might as well get your money's worth instead of dropping it the first day! – cnst Jan 23 '16 at 00:25
  • @cnst I didn't mention it but this is for development environments only so this is not really important. Thanks anyway =) – Alain Tiemblo Jan 23 '16 at 08:52
  • @AlainTiemblo, no, it's understood that it's for development only -- however, not following the best security practices is one way to get owned! – cnst Jan 23 '16 at 16:33
  • _Starting_ a service as root and having it _run_ as root are different things; homebrew per default will run php as a limited user (`_www`) rather than as your own user. Running as root is not great, but running as the current user has its own issues. [Link 2](https://gist.github.com/lifepillar/8b8e7f700e1a54d83b2e) shows how to start the service as root then have it switch users. Link 1 above says "run as root" but may be just a misphrasing. – Chris Burgess Jun 10 '16 at 17:08
  • Run php-fpm as root, have a compromised website (it happens) and there you go some hacker has root access to your server. – Rolf Apr 01 '17 at 20:50
3

Better practice is to reinstall php with

brew install --with-fpm --with-homebrew-curl --with-homebrew-openssl --with-imap --with-homebrew-libxslt --without-snmp php56

and then reinstall curl with

brew install --with-openssl curl
Marek Ruszczyk
  • 100
  • 1
  • 8
  • For me the solution was to reinstall php without the `--with-imap` option. It seems to break curl requests, as reported on this github issue : https://github.com/Homebrew/homebrew-php/issues/2390 – Seb May 12 '16 at 18:17