I have developed a php script to transfer statistics from a legacy stats system for Wordpress Multiuser to Piwik. Now I want to transfer our back stats (about ~1 300 000 actions) using it, but it’s going too slow (about 3000 items per hour).
I think the reason is because I use the sites SitesManager.getSitesIdFromSiteUrl by calling it via HTTP.
I didn’t check the documentation closely enough, below is an example that works by putting the file in the root directory of your Piwik install.
However, the script is still running very slowly. Does anyone have any tips for speeding it up? I am using the Tracking API for inserting hits, and it is using a HTTP request for every new hit. I’d like to use it in the same way as SitesManager API below, is it possible?
/*
define('PIWIK_INCLUDE_PATH', realpath('..'));
define('PIWIK_USER_PATH', realpath('..'));
*/
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);
function piwik_id_by_url($site_url,$token_auth)
{
require_once "index.php";
require_once "core/API/Request.php";
Piwik_FrontController::getInstance()->init();
// This inits the API Request with the specified parameters
$request = new Piwik_API_Request('
method=SitesManager.getSitesIdFromSiteUrl
&url='.$site_url.'
&format=XML
&token_auth='.$token_auth.'
');
// Calls the API and fetch XML data back
$reply = $request->process();
preg_match('/\<idsite\>(.+)\<\/idsite\>/', $reply, $matches);
if(isset($matches[1]))
return $matches[1];
else
return null;
}
$site_id = piwik_id_by_url('http://my.site.com','TOKEN AUTH');
echo $site_id;
I am still getting online 3-4000 items per hour with this.
Can you advise on how I can add visits quicker than via the PiwikTracker.php method?
Edit: After benchmarking, it seems that the query that creates new visitors seems to be running very slowly. If I file all users under the same IP I get speeds similar to what you describe. (~200/second), but whenever a new IP is processed everything halts for 2-10 seconds.