No way to get current thread ID
We need something like zend_thread_id to get the ID of the thread currently executing the PHP code.
This is important to us because our front-end PHP code uses pfsockopen to communicate with one of many servers running our back-end C++ business logic. We want each thread to have just a single connection open to a random back-end server. With PHP, we'd use getmypid to pick a consistent server to pfsockopen each time. With HHVM, getmypid returns the same value no matter which worker thread you're on, so we're now unable to effectively distribute the load to our backend servers. Our only choices now are to either have each box running HHVM connect to the same backend server every time or have each HHVM worker thread have multiple persistent connections to multiple backend servers, neither of which are ideal.
Essentially our problem is that the persistent socket opened by pfsockopen is stored in thread-local storage, but we have no way to know or predict what is already in that thread-local storage.
hphp_get_thread_id() or hphp_gettid() depending on if you want the pthread_self() value or the gettid() value.
Yup, those should both be what you're looking for, thanks, @simonwelsh
That works. Thanks! FWIW, I can't find these mentioned in any documentation.
Hmm, open an issue over at https://github.com/hhvm/hack-hhvm-docs