No-network Tracking API (PHP)

Hello

I’m currently injecting my own logs in a piwik databse using the PHP Tracking API[/url] ( my precedent post: [url=http://forum.piwik.org/read.php?3,74015,74015#msg-74015]Visit injection ).

As Matt said, “[…] not the fastest way but it will work […]”. I saw that the API access method is a HTTP call (using curl if i’m right). Is there a way to avoid this network call and call directly PHP classes ?

PS: On Tracking API piwik page, there is this line in PHP example:


[...]
$t->setCustomData( array('id' => 10, 'name' => 'test') );
[...]

… but i don’t see the setCustomData method in PiwikTracker class (maybe it’s an old one).

I’ve updated the doc: Tracking API - Analytics Platform - Matomo

Currently there is no way to avoid the calls, but this would be fairly easy if you set all variables in the _GET array, then copy paste the content of piwik.php in your script.

However I think there are memory leaks in the tracker, so it may fail after few hundreds or thousands visits - you are welcome to send patches with your code and/or improvements!

Thank you Matt, I will try with injecting in $_GET array.
If I can correct memory leaks at the same time, I will send patch.

Matt, I follow your lead. Here are my results for a simple test:
[ul]
[li] Using native API (HTTP call using curl): ~ 0.052 second / injection
[/li][li] Using API in a roundabout way (manualy filling $_GET array, without HTTP call) : ~ 0.046 s / injection. That’s a progress, but not significant enough in my sense…
[/li][/ul]

Of course, thoses mesures are very arch dependant.

During the test, I was surprised to note that some of the injections were terribly slow ( ~ 15 to 20 seconds for one injection ). The responsible code section is in core/Tracker/Visit.php -> handleNewVisit method -> L484


[...]
// This call can take more than 15 seconds sometimes
Piwik_PostEvent('Tracker.newVisitorInformation', $this->visitorInfo);
[...]

You will surely know better than me what’s happening here.

Yes it will be the Provider plugin which does network call, see Bulk load Piwik logs with documented API: improved tracking performance, allow performance testing · Issue #5554 · matomo-org/matomo · GitHub and investigate and implement gethostbyaddr() alternatives · Issue #2152 · matomo-org/matomo · GitHub