Piwik API - get an autostart.session error


#1

I am having problems with using the API. I am trying to include some API calls into a Yii framework application but i get the following error: session has already been started by session.auto-start or session_start()

I did a forum search, checked that the folders are writable,session.auto_start 0, etc. Same results.

Tested the solution found here still get the error.

When I call the file outside of the Yii app everythings works ok, but now within the application.

Code below:


<?php
use Piwik\API\Request;
use Piwik\FrontController;

define('PIWIK_INCLUDE_PATH', realpath('\wamp\www\piwik'));
define('PIWIK_USER_PATH', realpath('\wamp\www\piwik'));
define('PIWIK_ENABLE_DISPATCH', false);
define('PIWIK_ENABLE_ERROR_HANDLER', false);
define('PIWIK_ENABLE_SESSION_START', false);
require_once PIWIK_INCLUDE_PATH . "\index.php";
require_once PIWIK_INCLUDE_PATH . "\core\API\Request.php";
// if you prefer not to include 'index.php', you must also define here PIWIK_DOCUMENT_ROOT
// and include "libs/upgradephp/upgrade.php" and "core/Loader.php"


FrontController::getInstance()->init();

// This inits the API Request with the specified parameters
function piwikRequest($piwikSiteId,$piwikMethod,$piwikPeriod,$piwikDate)
{
  $piwikGetData = new Request
  ('
    method='. $piwikMethod .'
    &idSite='. $piwikSiteId .'
    &period='. $piwikPeriod .'
    &date='. $piwikDate .'
   &segment=customVariableName1==Mailing
    &format=php
    &serialize=1
    &token_auth=token
  ');
  $piwikGetData = $piwikGetData->process();
  return $piwikGetData;
}

?>

<?php 
function vizite()
{
$piwik = piwikRequest('1','VisitsSummary.getVisits','month','last1');
$arr = unserialize($piwik);
$vizite= reset($arr);
echo $vizite;
}
 ?>


Any clues ?


#2

I also get multiple errors like the one below:

There is an error. Please report the message (Piwik 2.4.0) and full backtrace in the Piwik forums (please do a Search first as it might have been reported already!).

Warning: include(Zend_Db_Statement_Pdo.php): failed to open stream: No such file or directory in C:\wamp\www\apps\common\framework\YiiBase.php on line 427

Backtrace -->

#0 Piwik\Error::errorHandler(…) called at [C:\wamp\www\apps\common\framework\YiiBase.php:427]
#1 YiiBase::autoload(…) called at [C:\wamp\www\apps\common\framework\YiiBase.php:427]
#2 YiiBase::autoload(…) called at [:]
#3 spl_autoload_call(…) called at [:]
#4 class_exists(…) called at [C:\wamp\www\piwik\libs\Zend\Db\Adapter\Pdo\Abstract.php:180]
#5 Zend_Db_Adapter_Pdo_Abstract->prepare(…) called at [C:\wamp\www\piwik\libs\Zend\Db\Adapter\Abstract.php:478]
#6 Zend_Db_Adapter_Abstract->query(…) called at [C:\wamp\www\piwik\libs\Zend\Db\Adapter\Pdo\Abstract.php:238]
#7 Zend_Db_Adapter_Pdo_Abstract->query(…) called at [C:\wamp\www\piwik\core\Db\Adapter\Pdo\Mysql.php:229]
#8 Piwik\Db\Adapter\Pdo\Mysql->query(…) called at [C:\wamp\www\piwik\libs\Zend\Db\Adapter\Abstract.php:736]
#9 Zend_Db_Adapter_Abstract->fetchAll(…) called at [C:\wamp\www\piwik\core\Db.php:179]
#10 Piwik\Db::fetchAll(…) called at [C:\wamp\www\piwik\core\Option.php:240]
#11 Piwik\Option->autoload(…) called at [C:\wamp\www\piwik\core\Option.php:161]
#12 Piwik\Option->getValue(…) called at [C:\wamp\www\piwik\core\Option.php:46]
#13 Piwik\Option::get(…) called at [C:\wamp\www\piwik\core\FrontController.php:286]
#14 Piwik\FrontController->init(…) called at [C:\wamp\www\piwik\core\dispatch.php:33]
#15 require_once(…) called at [C:\wamp\www\piwik\index.php:47]
#16 require_once(…) called at [C:\wamp\www\test2.php:10]
#17 require(…) called at [C:\wamp\www\apps\customer\views\campaigns\stats\piwik.php:15]
#18 require(…) called at [C:\wamp\www\apps\common\framework\web\CBaseController.php:126]
#19 CBaseController->renderInternal(…) called at [C:\wamp\www\apps\common\components\web\BaseController.php:245]
#20 BaseController->renderInternal(…) called at [C:\wamp\www\apps\common\framework\web\CBaseController.php:95]
#21 CBaseController->renderFile(…) called at [C:\wamp\www\apps\common\framework\web\CController.php:869]
#22 CController->renderPartial(…) called at [C:\wamp\www\apps\customer\views\campaigns\overview.php:145]
#23 require(…) called at [C:\wamp\www\apps\common\framework\web\CBaseController.php:126]
#24 CBaseController->renderInternal(…) called at [C:\wamp\www\apps\common\components\web\BaseController.php:245]
#25 BaseController->renderInternal(…) called at [C:\wamp\www\apps\common\framework\web\CBaseController.php:95]
#26 CBaseController->renderFile(…) called at [C:\wamp\www\apps\common\framework\web\CController.php:869]
#27 CController->renderPartial(…) called at [C:\wamp\www\apps\common\framework\web\CController.php:782]
#28 CController->render(…) called at [C:\wamp\www\apps\customer\controllers\CampaignsController.php:99]
#29 CampaignsController->actionOverview(…) called at [:]
#30 ReflectionMethod->invokeArgs(…) called at [C:\wamp\www\apps\common\framework\web\actions\CAction.php:108]
#31 CAction->runWithParamsInternal(…) called at [C:\wamp\www\apps\common\framework\web\actions\CInlineAction.php:47]
#32 CInlineAction->runWithParams(…) called at [C:\wamp\www\apps\common\framework\web\CController.php:308]
#33 CController->runAction(…) called at [C:\wamp\www\apps\common\framework\web\filters\CFilterChain.php:133]
#34 CFilterChain->run(…) called at [C:\wamp\www\apps\common\framework\web\CController.php:291]
#35 CController->runActionWithFilters(…) called at [C:\wamp\www\apps\common\framework\web\CController.php:265]
#36 CController->run(…) called at [C:\wamp\www\apps\common\framework\web\CWebApplication.php:282]
#37 CWebApplication->runController(…) called at [C:\wamp\www\apps\common\framework\web\CWebApplication.php:141]
#38 CWebApplication->processRequest(…) called at [C:\wamp\www\apps\common\framework\base\CApplication.php:180]
#39 CApplication->run(…) called at [C:\wamp\www\apps\init.php:189]
#40 require_once(…) called at [C:\wamp\www\customer\index.php:18]