3

I am developing a webpage that uses the Dropbox SDK to do some things. Most of this happens through the CLI but one particular thing must be done in the browser. I stumbled across an interesting issue, though.

$dbxClient = new dbx\Client($accountToken, 'xxx/' . VERSION);
$folderMetadata = $dbxClient->getMetadataWithChildren("/");

Running this code works just fine in CLI. Running it in the browser however gives me a 502. Being baffled I started up xdebug and traced where the problem appears. I found out, that Dropbox' curl-call was causing it so I wrote a small example script to see, if curl works at all. It does not.

<?php
    $ch = curl_init(); 
    curl_setopt($ch, CURLOPT_URL, "https://example.com"); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $output = curl_exec($ch); 

    curl_close($ch);
    echo $output;

Running this code in a browser gives a 502 instantly. If I remove https:// or make it a http:// (or run it in CLI) it works, though. The problem seems to be in PHP7 + curl + SSL. Adding curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); does NOT work.

What can I do to find out, why this happens and how I can solve it?

System Infos:

  • OS X 10.11.2
  • nginx 1.8.0, installed via homebrew
  • PHP 7.0.3, installed via homebrew
  • curl 7.43.0, installed via homebrew
  • OpenSSL 1.0.2f, installed via homebrew
Benjamin Schmidt
  • 1,051
  • 13
  • 29

1 Answers1

9

Sooo... after a LOT of investigation, I finally found a solution. Hopefully this will help future Googlers.

Step 1: Investigate what is happening.

Since I am using homebrew's php70-package, directories are a little different on OS X than Linux. I needed to find the php-fpm.conf. By examining the homebrew.*.plist-file created by homebrew I found it to be in /usr/local/etc/php/7.0/php-fpm.conf.

After that, I looked for the binary which, luckily, is noted down in the plist as well. For me it's in /usr/local/opt/php70/sbin/php-fpm.

I modified the config file to write a log file in /var/log/php-fpm.log:

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

I gave /var/log/php-fpm.log chmod 0777 (because I'm lazy), started up php-fpm again (launchctl load -w /path/to/php-fpm.plist) and tail'ed the new log file: tail -f /var/log/php-fpm.log

This is what I found (and what Googlers might look for):

WARNING: [pool www] child 28580 exited on signal 11 (SIGSEGV) after 1.726773 seconds from start

So a segmentation fault is happening.


Step 2: Fix SIGSEGV

Using the newly found information I google'd what could be the reason for the segmentation fault. I couldn't find anything on the first few pages that helped but on one of the later pages, I found this link: https://stackoverflow.com/a/34951784/1486930

What it says is:

I experienced same problem early and fixed it with running php-fpm as root.

and

You just killed me. Running php-fpm as root just works well! Thanks!!

So this is what I did. I stopped php-fpm again and manually ran it as root:

sudo /usr/local/opt/php70/sbin/php-fpm --fpm-config /usr/local/etc/php/7.0/php-fpm.conf

And see, it works! I have no idea why that is the case but indeed running it as root "fixes" it.

I hope to have helped.

Community
  • 1
  • 1
Benjamin Schmidt
  • 1,051
  • 13
  • 29
  • Runing php-fpm as root worked for me too, but I found that the problem was coming from `--with-imap` option. I uninstalled php and reinstalled it without imap and all works good. I don't need imap, but for those who need it, it's a problem. The issue is reported here https://github.com/Homebrew/homebrew-php/issues/2390 – Seb May 12 '16 at 18:13
  • 1
    Man! I've been trying to fix this since morning -- I want to buy you a beer! – shyam Jul 14 '16 at 17:56
  • 1
    2021 and i solved this by running fpm as root (installed using macports): `sudo /opt/local/sbin/php-fpm74 --fpm-config /opt/local/etc/php74/php-fpm.conf` – dehart Sep 23 '21 at 12:15