php-ga-measurement-protocol icon indicating copy to clipboard operation
php-ga-measurement-protocol copied to clipboard

setAsyncRequest implementation is broken

Open borkor opened this issue 7 years ago • 6 comments

After upgrading to v2.* setAsyncRequest has completely blocked complete execution of $analytics->setAsyncRequest(true)->sendPageview();

I believe that this is might be the issue related to usage of guzzlehttp. Had to completely disable asynchronous execution. Any thoughts on this?

borkor avatar May 04 '17 07:05 borkor

It may have to do with the guzzlehttp implementation, yes. This was done in this PR: https://github.com/theiconic/php-ga-measurement-protocol/pull/6

A quick google of the issue guided me to this thread where I see you commented as well, I can see in our code that we are not using that tick method mentioned. https://github.com/guzzle/guzzle/issues/1127

I'll look at this over the next few days, but if you think you can fix it feel free to open a PR for it.

jorgeborges avatar May 05 '17 02:05 jorgeborges

Asynchronous method should removed from future releases.

There are a whole bunch of issues in guzzle implementation regarding async requests. As it is now in php-ga-measurement-protocol it is misleading and making people believe this works as reactphp/promise.

Down to the point. Curl implementation in PHP is not asynchronous.

borkor avatar May 12 '17 11:05 borkor

I'll remove it from the current README for the time being...

I'm pretty sure this was working as I test it personally in v1 using Guzzle 5, I think it was indeed using ReactPHP along with promises, check out the composer.lock to see that it was being required before https://github.com/theiconic/php-ga-measurement-protocol/blob/v1/composer.lock

However, it seems to have broken when we upgraded to Guzzle 6, if you check the current composer.lock, React is not there anymore.

I found a good article on how to make Guzzle 6 async using React: http://stephencoakley.com/2015/06/11/integrating-guzzle-6-asynchronous-requests-with-reactphp

But then again, I also want to implement Http Plug to not couple with Guzzle anymore http://httplug.io/

I'll study these options and see if I fix it or remove it altogether from the next big release. Thanks @borkor for reporting the bug.

jorgeborges avatar May 14 '17 07:05 jorgeborges

In general, you have to call wait() for the async requests with Guzzle (which kinda destroy the purpose)....

yellow1912 avatar Oct 10 '17 10:10 yellow1912

so this bug still exists, I guess it's possible to fix?

lapswr avatar Mar 12 '19 13:03 lapswr

If async isn't working, the approach I'd take is to send all your analytics events after flushing the response, so that they don't slow down the page response time. If you're using PHP-FPM, you can flush the response using fastcgi_finish_request(). This sends the response to the client and closes the connection, but still lets you execute some other PHP code.

Daniel15 avatar Sep 05 '19 06:09 Daniel15