Skip to content

Instantly share code, notes, and snippets.

@edorian
Last active February 10, 2023 13:43
Show Gist options
  • Save edorian/e94bea3737c07dda86ab9ed1657dacc3 to your computer and use it in GitHub Desktop.
Save edorian/e94bea3737c07dda86ab9ed1657dacc3 to your computer and use it in GitHub Desktop.
PHP Prozess hanging in curl when using Guzzle or Symfony HttpClient

PHP Prozess hanging in curl when using Guzzle or Symfony HttpClient

A couple of month ago we ran into an issue with hanging PHP processes during/after HTTP calls.

Today another friend of mine ran into that issue, so here some notes in the hopes that this might be helpful to someone :)

Diagnose

strace the hanging process and see if it hangs in rt_sigaction

sudo strace -ttfp $pid
11:25:04.663911 rt_sigaction(SIGPIPE, NULL, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f763229e090}, 8) = 0
11:25:04.663974 rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f763229e090}, NULL, 8) = 0
11:25:04.664026 rt_sigaction(SIGPIPE, {sa_handler=SIG_IGN, sa_mask=[PIPE], sa_flags=SA_RESTORER|SA_RESTART, sa_restorer=0x7f763229e090}, NULL, 8) = 0

And/or confirm via gdb

If you don't have debug symbols installed, this will look differently:

sudo gdb -p $pid bt
(gdb) bt
#0  0x00007fbfef531166 in __GI___libc_sigaction (sig=sig@entry=13, act=act@entry=0x7ffd98161290, oact=oact@entry=0x0) at ../sysdeps/unix/sysv/linux/sigaction.c:58
#1  0x00007fbfef531299 in __GI___sigaction (sig=sig@entry=13, act=act@entry=0x7ffd98161290, oact=oact@entry=0x0) at ../nptl/sigaction.c:30
#2  0x00007fbfece84f2a in sigpipe_ignore (ig=ig@entry=0x7ffd98161340, data=<optimized out>) at sigpipe.h:56
#3  0x00007fbfece85a42 in sigpipe_ignore (ig=0x7ffd98161340, data=<optimized out>) at sigpipe.h:48
#4  Curl_conncache_close_all_connections (connc=connc@entry=0x55863df2b750) at conncache.c:564
#5  0x00007fbfece70a5e in curl_share_cleanup (share=0x55863df2b730) at share.c:198
#6  0x00007fbfed42e1f1 in curl_share_free_obj (object=0x7fbfe91c5ba8) at ./ext/curl/share.c:160
#7  0x000055863c548833 in zend_objects_store_free_object_storage (objects=objects@entry=0x55863c737988 <executor_globals+840>, fast_shutdown=fast_shutdown@entry=true) at ./Zend/zend_objects_API.c:109
#8  0x000055863c4a7b1a in zend_shutdown_executor_values (fast_shutdown=fast_shutdown@entry=true) at ./Zend/zend_execute_API.c:386
#9  0x000055863c4a7f93 in shutdown_executor () at ./Zend/zend_execute_API.c:403
#10 0x000055863c4b7eb3 in zend_deactivate () at ./Zend/zend.c:1271
#11 0x000055863c453c56 in php_request_shutdown (dummy=<optimized out>) at ./main/main.c:1847
#12 0x000055863c59fd80 in do_cli (argc=10, argv=0x55863db55150) at ./sapi/cli/php_cli.c:1135
#13 0x000055863c2f6f68 in main (argc=10, argv=0x55863db55150) at ./sapi/cli/php_cli.c:1367

Investigation

A bit of digging led me to the following:

curl/curl@c069027#diff-daf91468c288f8c97776ec9805e160a8a3bcb52e0001103d35b2079b7e842dd4R543 & curl/curl#4915 GCP issue on the topic: googleapis/google-cloud-cpp#3860

Links from along the way:

Fix & Validation

Updating to a new libcurl version solved the issue.

To test this for only one PHP process.

Build curl:

wget https://github.com/curl/curl/releases/download/curl-7_87_0/curl-7.87.0.tar.gz
tar -zxf curl-7_87_0.tar.gz 
cd curl-7.87.0/
./buildconf
./configure --with-openssl
make

From there, you can run PHP with the new Curl version:

LD_LIBRARY_PATH="/home/edo/curl/lib/.libs/" php -r 'var_dump(curl_version()["version"]);'
string(10) "7.87.0-DEV"

For us, the problems went away with this updated version so we could roll it out on our systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment