0

I have a php library which exposes a few apis which are latency sensitive. There is also a need to capture logs and metrics relevant to these aforementioned apis and send the log and metric data aggregated to a http/https endpoint. Log and metric aggregation and publishing of the same should not impact the api latencies.

Im new to PHP and have found out that there isn't support for asynchronous implementations as there aren't interrupts in the language.

Usage of queueing mechanisms like ActiveMq and the like is also not an option.

PThreads is also not an option as I do not want to make any assumptions on PHP version as my code runs as a library on servers potentially running different PHP versions.

The best I could come up with so far is to have a cron schedule the run of a script that publishes log and metric data but what i dont like about this approach is that it is involved and needs to be done on each machine running the php library.

Any suggestions on how to achieve this in a better way ?

EDIT : Added why Pthreads is not an option.

ping
  • 1,229
  • 3
  • 21
  • 41
  • I forgot to mention how pThread is also not an option, Pthreads was introduced in a later version of PHP and this being a library implementation, can not make any assumptions on PHP versions. I will edit my original question to cover this, thanks!. – ping Feb 26 '17 at 04:08
  • 1
    You could possibly run an `exec` of a script with the `&` at the end to make it a background process. Exec has been around for a while now. Check http://stackoverflow.com/questions/222414/asynchronous-shell-exec-in-php – apokryfos Feb 26 '17 at 09:02
  • This has worked for me. Had this been an answer, i would have accepted. – ping Mar 14 '17 at 13:06
  • You could answer your own question with more precise code. That comment is pretty generic. – apokryfos Mar 14 '17 at 13:21

0 Answers0