Archive for php
xdebug trace file parser
November 18th, 2009 • 7 comments freebies, php, snippets, software, xdebug

When I am trying to optimize my PHP code, one of my prefered tools is xdebug. It provides me with excellent error messages, outputs code tracing files & insight into memory usage.
By using kcachegrind or webgrind – wincachegrind crashes *all* the time – to parse the cachegrind files created by xdebug, you get a good idea of what your code is doing most of the time. It’ll show you which functions are called, by who, which arguments are passed and tons more. Check it out.
Now, there was one small thing I couldn’t find anywhere. A program to parse the trace files that xdebug generates. True, xdebug already provides the option to output this information into HTML, but it’s not really what I was looking for. I want to get quick information in the blink of an eye! That’s why I have created my own trace file parser, based on PHP of course.
Read more »
xampp mysqli crashes apache
November 18th, 2009 • apache, mysql, php, windows, xampp
Is your XAMPP installation crashing apache when using the mysqli PHP functions on windows? The apache logs are not telling anything even when you have debug mode enabled? Are you getting something like “Faulting application apache.exe, version 2.2.11.0, faulting module ntdll.dll” or “Faulting application apache.exe, version 2.2.11.0, faulting module MSVCR71.dll.” ?
Really? Sure? Well here’s your solution…
Download the most recent version of php_mysqli.dll and place it in <yourxampdir>\php\ext directory.You might want to take a backup of the file you’re replacing in case it doesn’t work…
You can download the php_mysqli.dll righ here or you’ll have to find a recent version for your PHP version yourself.
Multiple memcache instances/servers on windows
May 11th, 2009 • 4 comments memcache, memcached, php, windows
Setting up memcache on windows is like taking candy from a baby. You can find all the information and the binaries for memcache at http://jehiah.cz/projects/memcached-win32/ . Note that these binaries will also work for x64 based windows.
A little trickier is to set up multiple instances of memcached on your windows machine. Basically you have to install the same memcache executable as many times as you want servers.
Installing memcache from the command line is simple:
sc create "Memcached11211" binPath= "E:\webserver\memcached.exe -d runservice -p 11211 -m 128" DisplayName= "Memcached11211" start= auto
Thus, for multiple instances this will be:
sc create "Memcached11211" binPath= "E:\webserver\memcached.exe -d runservice -p 11211 -m 15" DisplayName= "Memcached11211" start= auto
sc create "Memcached11212" binPath= "E:\webserver\memcached.exe -d runservice -p 11212 -m 15" DisplayName= "Memcached11212" start= auto
sc create "Memcached11213" binPath= "E:\webserver\memcached.exe -d runservice -p 11213 -m 15" DisplayName= "Memcached11213" start= auto
sc create "Memcached11214" binPath= "E:\webserver\memcached.exe -d runservice -p 11214 -m 15" DisplayName= "Memcached11214" start= auto
sc create "Memcached11215" binPath= "E:\webserver\memcached.exe -d runservice -p 11215 -m 15" DisplayName= "Memcached11215" start= auto
sc create "Memcached11216" binPath= "E:\webserver\memcached.exe -d runservice -p 11216 -m 15" DisplayName= "Memcached11216" start= auto
sc create "Memcached11217" binPath= "E:\webserver\memcached.exe -d runservice -p 11217 -m 15" DisplayName= "Memcached11217" start= auto
sc create "Memcached11218" binPath= "E:\webserver\memcached.exe -d runservice -p 11218 -m 15" DisplayName= "Memcached11218" start= auto
sc create "Memcached11219" binPath= "E:\webserver\memcached.exe -d runservice -p 11219 -m 15" DisplayName= "Memcached11219" start= auto
sc create "Memcached11220" binPath= "E:\webserver\memcached.exe -d runservice -p 11220 -m 15" DisplayName= "Memcached11220" start= auto
sc create "Memcached11221" binPath= "E:\webserver\memcached.exe -d runservice -p 11221 -m 15" DisplayName= "Memcached11221" start= auto
sc create "Memcached11222" binPath= "E:\webserver\memcached.exe -d runservice -p 11222 -m 15" DisplayName= "Memcached11222" start= auto
As you can see from the example above, you have to choose a different port for each memcache instance you are running.
memcache_connect() [function.memcache-connect]: Can’t connect to localhost:11211
May 11th, 2009 • 4 comments memcache, memcached, php, snippets
Encountered this error? It could be as simple as switching the host from localhost to 127.0.0.1
before:
<?php
$memcache_obj = memcache_connect('localhost', 11211);
after:
<?php
$memcache_obj = memcache_connect('127.0.0.1', 11211);
PHP Get monday, sunday, last monday & last sunday
August 22nd, 2008 • 5 comments php, snippets, Uncategorized
A function I’ve put togheter for a work-related project to get date of monday, sunday, last monday & last sunday.. Might add in next monday and sunday later.
/**
* Get Mondays and Sundays
*
* Get monday, sunday, last monday & last sunday
* Example usage:
* // to retreive the dates using today as starting point
* $mondaysAndSundays = getMondaysAndSundays();
* // to retreive the dates using a custom date as starting point
* $mondaysAndSundays = getMondaysAndSundays('1987-04-14');
*
* @param date $offset Provide a date from where to calculate from in strtotime() translatable format. If none is given, today's date will be used.
*
* @return array
*
*/
function getMondaysAndSundays($offset=false)
{
if(!$offset) $offset = strtotime(date('Y-m-d'));
else $offset = strtotime($offset);
// this week
if(date('w',$offset) == 1)
{
$mas['monday'] = date('Y-m-d',$offset);
}
else
{
$mas['monday'] = date('Y-m-d',strtotime("last Monday",$offset));
}
if(date('w',$offset) == 6)
{
$mas['sunday'] = date('Y-m-d',$offset);
}
else
{
$mas['sunday'] = date('Y-m-d',strtotime("next Sunday",$offset));
}
// last week
if(date('w',$offset) == 1)
{
$mas['lastmonday'] = date('Y-m-d',strtotime('-1 week',$offset));
}
else
{
$mas['lastmonday'] = date('Y-m-d',strtotime('-1 week', strtotime(date('Y-m-d',strtotime("last Monday",$offset)))));
}
if(date('w') == 6)
{
$mas['lastsunday'] = date('Y-m-d',strtotime('-1 week',$offset));
}
else
{
$mas['lastsunday'] = date('Y-m-d',strtotime("last Sunday",$offset));
}
return $mas;
}