# Can PHP elastic agent send custom message to APM service asynchronously?

**URL:** <https://discuss.elastic.co/t/can-php-elastic-agent-send-custom-message-to-apm-service-asynchronously/330344>\
**Category:** APM\
**Tags:** php\
**Created:** [April 20, 2023, 4:18am UTC](https://discuss.elastic.co/t/can-php-elastic-agent-send-custom-message-to-apm-service-asynchronously/330344 "2023-04-20T04:18:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![JasonREC](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@JasonREC](https://discuss.elastic.co/u/JasonREC)\
**Post date:** [April 20, 2023, 4:18am UTC](https://discuss.elastic.co/t/can-php-elastic-agent-send-custom-message-to-apm-service-asynchronously/330344/1 "2023-04-20T04:18:36Z")

</div>

I got 2 questions that confused me

1. I wonder if in the latest version of PHP apm agent, I can send custom message to APM server. like captureError, setContext which is nodeJS APM agent able to do

2. In some case, there is a huge a mount of request comes into my app server, and for each reqesut/transaction which hit my endpoint, I also want to attach some metadata in it, so the apm agents can sends it to the apm server. I wonder if adding elastic\_apm.async=true in the php.ini file can actully achieve the async mode of sending transaciton detail to apm server since I think the default set up is blocking (Correct me if I am wrong) which could have a chance to block my main business logic while sending data to apm server.

Thanks

---

<div class="post-metadata">

**Author:** ![Sergey\_Kleyman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sergey_kleyman/32/39333_2.png) [@Sergey\_Kleyman](https://discuss.elastic.co/u/Sergey_Kleyman)\
**Post date:** [April 20, 2023, 12:31pm UTC](https://discuss.elastic.co/t/can-php-elastic-agent-send-custom-message-to-apm-service-asynchronously/330344/2 "2023-04-20T12:31:49Z")

</div>

Hi @JasonREC

Regarding question #1 - the answer is yes, you can use PHP Agent's [public API](https://www.elastic.co/guide/en/apm/agent/php/current/public-api.html).

Regarding question #2 - when running in the context of a web service PHP Agent sends data to APM Server in the background thus not blocking the application. There is indeed a past limitation (that we are working to lift) - when running in the context of CLI application PHP Agent by default sends data to APM Server synchronously (and as a consequence blocking the application). It's possible to override that default by explicitly setting `async_backend_comm` configuration option to `true` (by using `elastic_apm.async_backend_comm` in `php.ini` or `ELASTIC_APM_ASYNC_BACKEND_COMM` environment variable).

---

<div class="post-metadata">

**Author:** ![JasonREC](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@JasonREC](https://discuss.elastic.co/u/JasonREC)\
**Post date:** [April 21, 2023, 3:10am UTC](https://discuss.elastic.co/t/can-php-elastic-agent-send-custom-message-to-apm-service-asynchronously/330344/3 "2023-04-21T03:10:09Z")

</div>

> [@Sergey\_Kleyman](#):
>
> elastic\_apm.async\_backend\_comm

@Sergey_Kleyman Thank you very much! very helpful

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 11, 2023, 11:10pm UTC](https://discuss.elastic.co/t/can-php-elastic-agent-send-custom-message-to-apm-service-asynchronously/330344/4 "2023-05-11T23:10:42Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
