jessecascio/querypro

Query Pro PHP Library

0.2.1 2015-06-23 22:37 UTC

README

PHP SDK for QueryPro

Usage

Install the latest version with composer require jessecascio/querypro

Add to self made wrapper class for all queries

<?php

use QueryPro;
use QueryPro\Handler;

class Database
{
	private $udp;
	
	public function __construct()
	{	
		$socket    = new QueryPro\Socket('127.0.0.1', 4444);
    	$this->udp = new Handler\SQL('application-name', $socket);
	}

	/**
	 * Example updating Database wrapper class
	 */
	public function query($query) 
	{
		// other important stuff

		// track query and duration
		$start  = microtime(true);
		$result = @mysql_query( $query, $this->dbh );
		$this->udp->batch($query, $start, microtime(true)); 

		// batch send query data via UDP
		$this->udp->send();

		// continue on
	}
}

Or Selectively track queries

<?php

use QueryPro;
use QueryPro\Handler;

$socket  = new QueryPro\Socket('127.0.0.1', 4444);
$handler = new Handler\SQL('application-name', $socket);

// only want to track these queries in application logic
$timer = microtime(true);
$database->query('SELECT * FROM TABLE');
$handler->batch('SELECT * FROM TABLE', $timer, microtime(true)); // track duration

// ...
$timer = microtime(true);
$database->query('SELECT * FROM OTHER');
$handler->batch('SELECT * FROM OTHER', $timer, microtime(true));

// batch send query data via UDP
$handler->send();