Skip to content
This repository has been archived by the owner on Jan 24, 2022. It is now read-only.

Commit

Permalink
Make sure auto start runs only once. Prevent tideways.load_library=1 …
Browse files Browse the repository at this point in the history
…and composer auto start to interfere.
  • Loading branch information
beberlei committed Mar 29, 2015
1 parent 9590eb3 commit bbefa7a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/scripts/auto_start.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
<?php

/** Check for auto starting the Profiler in Web and CLI (via Env Variable) */
if (ini_get("tideways.auto_start") || isset($_SERVER['TIDEWAYS_AUTO_START'])) {
if (php_sapi_name() !== "cli") {
/**
* In Web context we auto start with the framework transaction name
* configured in INI or ENV variable.
*/
if (ini_get("tideways.transaction_function")) {
\Tideways\Profiler::detectFrameworkTransaction(ini_get("tideways.transaction_function"));
} else if (isset($_SERVER['TIDEWAYS_TRANSACTION_FUNCTION'])) {
\Tideways\Profiler::detectFrameworkTransaction($_SERVER['TIDEWAYS_TRANSACTION_FUNCTION']);
if (ini_get("tideways.auto_start") || isset($_SERVER["TIDEWAYS_AUTO_START"])) {
if (\Tideways\Profiler::isStarted() === false) {
if (php_sapi_name() !== "cli") {
/**
* In Web context we auto start with the framework transaction name
* configured in INI or ENV variable.
*/
if (ini_get("tideways.transaction_function")) {
\Tideways\Profiler::detectFrameworkTransaction(ini_get("tideways.transaction_function"));
} else if (isset($_SERVER['TIDEWAYS_TRANSACTION_FUNCTION'])) {
\Tideways\Profiler::detectFrameworkTransaction($_SERVER["TIDEWAYS_TRANSACTION_FUNCTION"]);
}
\Tideways\Profiler::start();
} else if (php_sapi_name() === "cli" && !empty($_SERVER["TIDEWAYS_SESSION"]) && isset($_SERVER['argv'])) {
\Tideways\Profiler::start();
\Tideways\Profiler::setTransactionName("cli:" . basename($_SERVER['argv'][0]));
}
\Tideways\Profiler::start();
} else if (php_sapi_name() === "cli" && !empty($_SERVER['TIDEWAYS_SESSION'])) {
\Tideways\Profiler::start();
\Tideways\Profiler::setTransactionName("cli:" . basename($argv[0]));
}
}
22 changes: 22 additions & 0 deletions tests/cli-autostart-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

$_SERVER['TIDEWAYS_AUTO_START'] = 1;
$_SERVER['TIDEWAYS_APIKEY'] = $argv[1];

require_once __DIR__. '/../vendor/autoload.php';

function bar() {
}

function foo() {
for ($i = 0; $i < 10; $i++) {
bar();
}
}

foo();
if (\Tideways\Profiler::isStarted()) {
echo "Profiler started\n";
} else {
echo "Profiler *NOT* started\n";
}

0 comments on commit bbefa7a

Please sign in to comment.