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:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With