hhvm icon indicating copy to clipboard operation
hhvm copied to clipboard

No way to get current thread ID

Open apaloma opened this issue 12 years ago • 4 comments

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.

apaloma avatar Nov 21 '14 23:11 apaloma

hphp_get_thread_id() or hphp_gettid() depending on if you want the pthread_self() value or the gettid() value.

simonwelsh avatar Nov 22 '14 00:11 simonwelsh

Yup, those should both be what you're looking for, thanks, @simonwelsh

paulbiss avatar Nov 22 '14 00:11 paulbiss

That works. Thanks! FWIW, I can't find these mentioned in any documentation.

apaloma avatar Nov 22 '14 00:11 apaloma

Hmm, open an issue over at https://github.com/hhvm/hack-hhvm-docs

paulbiss avatar Nov 22 '14 03:11 paulbiss