Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to handle possibility of blocking curl requests #4

Closed
nonsenz opened this issue Jan 16, 2015 · 2 comments
Closed

How to handle possibility of blocking curl requests #4

nonsenz opened this issue Jan 16, 2015 · 2 comments

Comments

@nonsenz
Copy link

nonsenz commented Jan 16, 2015

Hi,
I'm a first time user of the piwik-php-tracker and I'm wondering how to integrate tracking in our project. I like to use it to trigger some events in the backend and send those to piwik so they can be viewed nicely in the piwik-UI. But I don't want to block the backend code with those calls. What if the piwik server does not answer? The default request-timeout is set to 600secs with a nice comment (https://github.com/piwik/piwik-php-tracker/blob/84a994a4d34a601a1b1da2c44a122807a1c4ad5b/PiwikTracker.php#L146). Maybe I'm wrong, but its sounds like a dangerous default. One can set the curl-timeout with ->setRequestTimeout() to a minimum of 1sec. But thats still a lot of time.
My question: is the piwik-php-tracker the right choice to track events out a complex webapp context? I could imagine to use pthreads (http://php.net/manual/de/book.pthreads.php) or overwriting the ->sendRequest() method to use CURLOPT_TIMEOUT_MS instead of CURLOPT_TIMEOUT to minimize the blocking. I'm not interested in the piwik-response atm.
How do you handle this in your projects?

@nonsenz
Copy link
Author

nonsenz commented Jan 20, 2015

After some more testing I'm not sure how to handle this because curl behaves not the way I want it to. On some systems CURLOPT_NOSIGNAL => 1 is needed to get the _MS stuff to work. More info about the can be found here. To have really short timeouts, the CURLOPT_TIMEOUT should be changed to CURLOPT_CONNECTTIMEOUT, because we still want to get the request send to piwik. I still have problems with timeouts < 100ms and I don't understand why.
ATM I think it's better to track actions in the frontend only. I could write data from the backend in the DOM and process it with some js-code in the frontend.
After all I would like to hear how you handle this in your projects.

@mattab mattab added this to the Backlog milestone Oct 30, 2015
@mattab
Copy link
Member

mattab commented Dec 27, 2016

@nonsenz you can customise the requestTimeout attribute and set it to 1 second. If that's not good enough, then don't use the doTrack* methods (which will use CURL or Fopen streams), and instead fetch the URL with calling getUrl* method and call yourself using your favorite flavor).

There's also the possibility to bulk requests using enableBulkTracking() which can sometimes be useful

Enables the bulk request feature. When used, each tracking action is stored until the doBulkTrack method is called. This method will send all tracking data at once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants