Items filtered by date: December 2015

Sunday, 22 February 2015 21:21

GrabPHP - Dump the system php.ini

To do a lot of php.ini overides you need to get the system php.ini before you can start but this can be a tricky thing. This script will read and then dump the system php.ini

  1. Alter the code below to fit your server and then create grab.php with the altered code and upload to your website public directory.

    <?
    copy('/usr/local/lib/php.ini', '/home/example/public_html/php.ini');
    ?>
    If you do not know your physical paths you can create a file called info.phpwith the following code, upload it to your root public folder and run it. The script will display all of the required information including the physical path.
    <? phpinfo() ?>
  2. Upload grab.php to your root public folder
  3. Browse to the file and run it. Assuming you loaded it to your root public_html folder then you should browse to
    http://www.example.com/grab.php
  4. This file will create a copy of your system php.ini file and dump it into your root public folder.
  5. Download the new php.ini to your PC
  6. Delete the php.ini and grab.php from your webserver

 

Published in PHP

The following snippets are simple methods of adding HTML and text in to the DOM tree with javascript.

//Add some text in to the variable sometext - note it adds it as text not html - also next section is required
var sometext = document.createTextNode("Z<br /><br />");

// This appends the variable some text to cellRightSel
cellRightSel.appendChild(sometext);

//--

// This adds the text straight on to cellRightSel, no variable required
cellRightSel.appendChild(document.createTextNode('Here is some syndicated content.'));

//-

// didnt work
cellRightSel.appendChild(create('<div>Hello!</div><br /><br />'));

//-

// this makes a variable newElement populated with the following html (this does actually paste the html)
var newElement = '<p id="foo">This is some dynamically added HTML. Yay!</p>';
var bodyElement = cellRightSel;
bodyElement.innerHTML = newElement + bodyElement.innerHTML;

// same as above but shorter and quickr, you can probably alter the order appropiately
cellRightSel.innerHTML = '<p id="foo">This is some dynamically added HTML. Yay!</p>' + cellRightSel.innerHTML;

 

Published in Javascript
Sunday, 22 February 2015 20:54

Flatten Arrays

This is my collection of php snippets that flatten arrays. There are scripts that work on traditional arrays and some that work on objects. I have tried to include where i got them from aswell.

1

// possibly from here - http://www.phpro.org/examples/Convert-Object-To-Array-With-PHP.html

/**
*
* Convert an object to an array
*
* @param    object  $object The object to convert
* @reeturn      array
*
*/
function objectToArray( $object )
{
	if( !is_object( $object ) && !is_array( $object ) )
	{
		return $object;
	}
	if( is_object( $object ) )
	{
		$object = get_object_vars( $object );
	}
	return array_map( 'objectToArray', $object );				
}

/*** convert the array to object ***/
//$array = objectToArray( $obj );

/*** show the array ***/
//print_r( $array );

2

// not all of these flatteners can handle objects or associative arrays, experiment to find one that works
// i think associated arrays are different, and require different looping


// see - http://stackoverflow.com/questions/1319903/how-to-flatten-a-multidimensional-array
function flatten(array $array)
{
	$return = array();
	array_walk_recursive($array, function($a) use (&$return) { $return[] = $a; });
	return $return;
}

// does not flatten array completely, same as above

function array_flatten($array)
{

	$return = array();
	
	   foreach ($array as $key => $value) {
		   if (is_array($value)){ $return = array_merge($return, array_flatten($value));}
		   else {$return[$key] = $value;}
				}
				
	return $return;

}

3

// WORKS
// this works but murders all the keys and flattens them all to strings
// see - http://www.cowburn.info/2012/03/17/flattening-a-multidimensional-array-in-php/	
// works on objects
function jon_flatten ($input)
{
$output = iterator_to_array(new RecursiveIteratorIterator(
new RecursiveArrayIterator($input)), FALSE);

return $output;
}

4

// see - http://stackoverflow.com/questions/526556/how-to-flatten-a-multi-dimensional-array-to-simple-one-in-php

function flatten_array($array, $preserve_keys = 0, &$out = array()) {
	# Flatten a multidimensional array to one dimension, optionally preserving keys.
	#
	# $array - the array to flatten
	# $preserve_keys - 0 (default) to not preserve keys, 1 to preserve string keys only, 2 to preserve all keys
	# $out - internal use argument for recursion
	foreach($array as $key => $child)
		if(is_array($child))
			$out = flatten_array($child, $preserve_keys, $out);
		elseif($preserve_keys + is_string($key) > 1)
			$out[$key] = $child;
		else
			$out[] = $child;
	return $out;
}

5

// flatten multidimensional arrary into single dimension
// see - http://davidwalsh.name/flatten-nested-arrays-php

function array_flatten($array,$return)
{
	for($x = 0; $x < count($array); $x++)
	{
		if(is_array($array[$x]))
		{
			$return = array_flatten($array[$x],$return);
		}
		else
		{
			if($array[$x])
			{
				$return[] = $array[$x];
			}
		}
	}
	return $return;
}

6

// flattenEachArrayToAnyDepth-------------------//
// see - http://davidwalsh.name/flatten-nested-arrays-php in the coments

//$res = array_flatten($myarray,array());
function array_flatten($array,$return){
	foreach($array as $key => $value){
		if(@is_array($value)){
			$return = $this->array_flatten($value,$return);
		}elseif(@$value){
			$return[$key] = $value;
		}
	}
	return $return;
}

7

// doesnt seem to work properely
// see - http://davidwalsh.name/flatten-nested-arrays-php#comment-56256}

/**
 * Flattens a nested array.
 *
 * Based on:
 * {@link http://davidwalsh.name/flatten-nested-arrays-php#comment-56256}
 *
 * @param array $array     - The array to flatten.
 * @param int   $max_depth - How many levels to flatten.  Negative numbers
 *                           mean flatten all levels.  Defaults to -1.
 * @param int   $_depth    - The current depth level.  Should be left alone.
 */
function array_flatten(array $array, $max_depth = -1, $_depth = 0) {
  $result = array();

  foreach ($array as $key => $value) {
	if (is_array($value) && ($max_depth < 0 || $_depth < $max_depth)) {
	  $flat = array_flatten($value, $max_depth, $_depth + 1);
	  if (is_string($key)) {
		$duplicate_keys = array_keys(array_intersect_key($array, $flat));
		foreach ($duplicate_keys as $k) {
		  $flat["$key.$k"] = $flat[$k];
		  unset($flat[$k]);
		}
	  }
	  $result = array_merge($result, $flat);
	}
	else {
	  if (is_string($key)) {
		$result[$key] = $value;
	  }
	  else {
		$result[] = $value;
	  }
	}
  }

  return $result;
}

8

// WORKS	
// this works but kills the keys
// see - http://davidwalsh.name/flatten-nested-arrays-php
function array_flatten($array, $return=array()) {
	foreach ($array AS $key => $value) {
		if(is_array($value))
		{
		$return = array_flatten($value,$return);
		}
		else
		{
			if($value)
			{
			$return[] = $value;
			}
		}
	}
return $return;

}

9

// Ennio Wolsink

// @Manu: if you replace $return[] = $value; with $return[$key] = $value; you get the preserve the index names of the source array(s). Don’t know if that’s everyone preference, but that was what I was looking for. If one wanted to make this optional, he could add a 3rd optional parameter to this function to indicate wether or not to preserve index names, like so:

function array_flatten($array, $return=array(), $preserve_index_names = false)
{
		foreach ($array AS $key => $value) {
				if(is_array($value)) {
				$return = array_flatten($value,$return, $preserve_index_names);
				}
				else {
					if($value) {
					if($preserve_index_names === false) {
					$return[] = $value;
					}
						else {
						$return[$key] = $value;
						}
					}
				}
		}

		return $return;
}

And then run it like so to get a flattened array back with index names preserved:

$result = array_flatten($input, array(), true);

And like this if you don’t want the index names preserved:

$result = array_flatten($input);

10

// recursively reduces deep arrays to single-dimensional arrays
// $preserve_keys: (0=>never, 1=>strings, 2=>always)
// see - http://www.php.net//manual/en/function.array-values.php
function array_flatten($array, $preserve_keys = 1, &$newArray = Array()) {
  foreach ($array as $key => $child) {
    if (is_array($child)) {
      $newArray =& array_flatten($child, $preserve_keys, $newArray);
    } elseif ($preserve_keys + is_string($key) > 1) {
      $newArray[$key] = $child;
    } else {
      $newArray[] = $child;
    }
  }
  return $newArray;
}

11

// same array_flatten function, compressed and preserving keys.
// see - http://www.php.net//manual/en/function.array-values.php
function array_flatten($a,$f=array()){
  if(!$a||!is_array($a))return '';
  foreach($a as $k=>$v){
    if(is_array($v))$f=self::array_flatten($v,$f);
    else $f[$k]=$v;
  }
  return $f;
}	

 

Published in PHP
Sunday, 22 February 2015 20:38

Dynamically stretch background images

This code allows you to stretch background images when you page expands to provide a better user experience.

Vertically Stretch Background Image

HTML

<link href="/global.css" rel="stylesheet" type="text/css" />
<table width="100%" height="100%" border="0"  cellpadding="0" cellspacing="0">
  <tr>
    <td class="header" colspan="2">&nbsp;</td>    
  </tr>
  <tr>
    <td class="top">&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="middle"><img src="/middle.jpg" alt="background image" id="bg" /></td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td class="bottom" colspan="2">&nbsp;</td>
  </tr>
</table>

CSS

.top {
	width: 130px;
	height: 143px;
	background: black url('top.jpg') left top no-repeat;
	}
.middle {
	width: 130px;
	height: 100%;
	/* background: url('middle.jpg') no-repeat; */
	background-size: 100%;
	}
td.middle img#bg {
	width:100%;
	height:100%;
	}
.bottom {
	height: 59px;
	background: #fff url('bottom.jpg') left top no-repeat;
	}

Although this code is rigged using tables the method can easily be changed to use <div> .

Click here for a demo of this code

Links

Published in HTML
Sunday, 22 February 2015 20:07

Disable Magic Quotes via htaccess

This is a method to disable 'Magic Quotes' when you need to turn them off for such things as joomla. The following instructions are to get your system php.ini file, disable Magic Quotes in this file, and then get the system to load the new file and overide the system php.ini using a command in your .htaccess file.

Please follow the instructions below:

  1. download a copy of the system php.ini (/usr/local/lib/php.ini)
  2. modified the following line
    ; Magic quotes for incoming GET/POST/Cookie data.
    magic_quotes_gpc = On
    To
    ; Magic quotes for incoming GET/POST/Cookie data.
    magic_quotes_gpc = Off
  3. upload the file to somewhere on your webserver, preferably outside of your public_html folders but not required
  4. create/edit your route .htaccess and add the following line which references the new php.ini file
    <IfModule mod_suphp.c>
      suPHP_ConfigPath /home/example/public_html
      <Files php.ini>
        order allow,deny
        deny from all
      </Files>
    </IfModule>
Published in htaccess
Sunday, 22 February 2015 19:05

Overriding the php.ini

There are a couple of ways to overide the PHP settings as defined in /usr/local/lib/php.ini (the system php.ini) and i will list them below.

  • if the specified .ini file does not exist default /usr/local/lib/php.ini is loaded
  • you do not need to use php.ini as the .ini filename, the system php.ini file will still get overidden no matter what name you give it as long as it is correctely specified. The only exception is that when using the 'php.ini in a folder' method, it must be called php.ini
  • in all of these method below you make the changes in the target php.ini file and are basically telling the system to use that instead.
  • when i mention php.ini, this can be replaced with 'Loaded Configuration File'

NB: DO NOT PUT php.ini IN THE PUBLIC_HTML, they can be read and downloaded., only put them in there or any subfolder if they are protected.

php.ini in a folder

You can just place a copy of your modified php.ini file, altered to your needs, in to any folder and all scripts run from that folder will run using the php.ini in the folder, instead of the system php.ini.

  • it takes all settings from the root htaccees file /usr/local/lib/php.ini and then overides them with what is in the new php.ini
  • this will be shown as the loaded php.ini file
  • Some settings can not be overidden with this method.
  • this is not recursive
  • php.ini will not work in directories where SetEnv PHPRC has been used because the 'Loaded Configuration File' has already been set via the htaccess file

suPHP

This is set in the .htaccess file and points to a php.ini of your choice. It is preferable to place this php.ini outside the public_html folders.

  • maintains current php.ini file but appears as the loaded php.ini file used.
  • It only overides what is written in it
  • i dont know if it is recusive

Examples

1 - This is the most basic of the command and will work for most people

suPHP_ConfigPath /home/example/php-folder/php.ini

2 - This example shows how you can put the php.ini in a public_html folder and prevent access to it. The suphp command will also not run unless the module is installed and this can prevent errors upon installation.

<IfModule mod_suphp.c>
  suPHP_ConfigPath /home/example/public_html
  <Files php.ini>
    order allow,deny
    deny from all
  </Files>
</IfModule>

SetENV PHPRC

This is set in the .htaccess file and points to a php.ini of your choice. It is preferable to place this php.ini outside the public_html folders.

  • becomes the loaded php.ini file
  • this method replaces the loaded php.ini, it does not use an overide mechanism
  • it is recursive
  • SetEnv PHPRC only works when using PHP as CGI, not when using php as an Apache Module
  • this method can be used to effectively remove 'disable_functions'

Examples

SetEnv PHPRC /home/example/php-folder/php.ini

Links

This assumes that you webhost company has already sideloaded the appropriate version of PHP you want to use. This is the .htaccess code required to tell the server to use the alternative version.

Sideload alternative version of PHP

Sideloading PHP allows you to have mulitple PHP versions running on the same hosting account/server. You have the default PHP version and then the sideloaded ones which you can access by using an alternative php.ini defined by a .htaccess file. Using suPHP will override the default php.ini recursively.

This code below is put in your .htaccess file and configures the host to use a sideloaded version of PHP, in this case PHP 5.5.

# Custom Legacy PHP 5.5 handler placed by host
    AddType application/x-httpd-php55 .php5 .php4 .php .php3 .php2 .phtml
    suPHP_ConfigPath /usr/local/lib/php55.ini
# End Custom Legacy PHP 5.5 handler placed by host

The target version of PHP needs to be installed by your host provider for this to work.

Published in General

These instructions assume your phone has been unlocked/rooted, if not you should use the cyanogenmod windows installer to do the work for you.

The current ROM I am using is cm-11-20141230-NIGHTLY-i9100 on my Samsung Galaxy S2 i9100 (intl) from http://download.cyanogenmod.org/?device=i9100 and I used GApps from http://slimroms.net/index.php/downloads/dlsearch/viewcategory/1150-addons4-4 - I used the Slim_mini_gapps.4.4.4.build.8.x-385 og

When you install a ROM

When install a ROM it just replaces the /system/ partition (and cyanogen it also does the /boot/ partition) thus all system settings are saved which are stored in /data/

Wiping the system Partition

Does the following

  • seems to do nothing in the sense of when you re-install your ROM, all settings are maintained
  • you need to reconnect your google account, possibly android keeps google account info in the /system/ partition

Notes

General Installation Notes

CM 11 ROM Notes

Other Notes

Android 5.1.1 on Samsung S2 Links

Published in Android
Saturday, 21 February 2015 22:00

How I repaired missing drives on my Samsung S2

The problem

Both my internal and external SDCards dissapered on my Samsung s2. The external SD Card when I removed it and put it in my windows PC it read normally and had no errors.

Cause

I do not know what the exact cause is but possibly one of the following, but you should consider that both of my SD Cards stopped working.

  • Virus
  • Corrupt file system
  • 3rd party App
  • Faulty Hardware

So Basically it appears that the partitions are mounted but the filessytem that is mounted is corrupt so it almost appears as if they are not mounted.

Solution

After days of research I did the following to get my SD Cards to work

External SD Card (sdcard1)

  • I copied the stuff of the card to my windows PC
  • Formatted the card in my windows PC as FAT32 (or whatever its format was)

    If this does not work, change its type FAT32/extFAT and see if it works and then change back again. Only CM11+ supports extFat

Internal Card (sdcard / sdcard0)

This is more tricky because it cannot be removed and this solution is currently the best I could come up with

  • Boot in to clockworkmod(CWM)
  • Format the sdcard via CWM by doing the following:
  1. ‘mounts and storage’
  2. ‘format /sdcard’ (if unsure remove your external SD Card)
  3. Select default (unless you know what your file system is)
  • Do file recovery on the newly visible drive to recover your files
  1. DiskDigger – Use on the phone itself. The free version will recover images and .mp4 to a selectable location ie your external SD Card. Seems Quite Good
  2. Windows Based Recovery – Mount SD Cards as USB Mass Storage
    (possibly run this from CWM), then runt he software

Research

These are my notes on all of the googleing and trying of different solutions

Works (or partially works)

Stuff That Does Not Work

  • Upgrading the installed version of CM/Android – The problem persists exactly the same
  • updating the ROM does not fix the missing internal SD Card issue (cyanogen updates all keep the current files apps etc..)
    useful if you cannot boot you can do a repair install.
  • wiping system partition + re-install of CM
  • these apps make no difference to fixing the issue
    • mount /system (rw / r0)
    • sd card auto remount w/ad
    • sd card check

Stuff That Might Have Merit – But I possibly did wrong!

  • possibly delete the mount points before recreating them

Stuff To Try

UseFul Apps

  • DiskDigger for android – This can be useful for a couple of reasons
    • Can be used to show mount points and their mappings to devices
    • Recover files from damaged partitions. The partitions need to be mounted and the free version does images and mp4 videos. It should be noted it does not recover folder structure
  • DiskUsage – shows you where all your space is being used
  • Diskinfo - this apps shows disk info mounted and unmounted. Excellent for disk diagnostics

Other Notes

Misc

Terminal

The terminal is a powerful tool to be able to help diagnose partion and disk issues

Useful Terminal Commands

  • cd ..   (notice space after cd)
  • umount (notice no 'n')
  • cd /mnt
  • cd mnt
  • mount (with not switches shows the active mounts)
  • cat /proc/partitions – shows partitions
  • df – shows file systems
  • fdisk – perfom actions on the disks and partitions
  • fsck - ? possibly does disk repair, not native to android?
  • dev_mount – device mounting command, might not be readily available in terminal
  • df - lists all partitions
  • mount – (without any switches) show all mount points
  • rmdir
  • rm

Mounting

** add websites where appropriate to my links directory

Published in Android
Saturday, 21 February 2015 21:58

How I flashed my Samsung S2

My Samsung was already rooted so if yours is skip to the next section………

Ways to flash a Samsung

  • Use ODIN from windows to flash a rooted kernel or a full ROM if your phone is not rooted at all. Most Full ROMS will have a rooted kernel
  • If your phone is rooted you can install Mobile ODIN and install a new Kernel throught that.
    ODIN lite – I think only flashes kernels
  • If your bootloader has CWM (clock work mods), you can use this to update the ROM
    newer ROMS tend to need newer CWM to flash them

{Picture of odin here}

In the picture you can see the ROM is cut up into sections

  1. Kernel
  2. Restore
  3. OS
  4. Data
  • ROM sections can be flashed independently
  • The stock kernel has a brick bug in it
  • Odin is samsungs direct flasher software
  • You can use CWM to flash once it is installed on a rooted phone
  • Rooted phone is made by modifying the kernel
  • CWM is flashed into the recovery partition
  • So flashing a ROM can either flash all areas or just the particular segments, but usually all
  • Mobile ODIN is an app for running off the phone itself with similar functionality to ODIN
  • You can flash with clockworkmod (CWM)/ODIN/Mobile ODIN

So I Flashed by

Files I used for a successful flash

  1. Siyah-s2-v6.0b5.tar (brick bug free)
  2. MobileODINLite-v4.00.apk
  3. MobileODIN_FlashKernel_I9100-v2.0.apk

My Phone was already Rooted

  1. Installed mobile ODIN on my phone
  2. Installed the extra addon for Mobile ODIN specific to my phone, on my phone
  3. Copied the kernel, Siyah-s2-v6.0b5.tar, this is the ODIN version of the kernel
  4. Ran Mobile ODIN and allowed permanent root access
  5. Selected the Siyah-s2-v6.0b5.tar file
  6. Flashed

Some other notes?

  • CWM is in the kernel ? Can be in the Kernel or the Recovery ?
  • I got a status 7 error when I tried installing the Siyah-s2-v6.0b5-CWM.zip (CWM version) of the kernel via CWM. This is because the version of CWM was not capable of flashing this file because it was to new. Flashing the ODIN version of the file fixed the installation issue (the author notes this on his website)
  • Can I do a factory reset without loosing my custom ROM
  • A modern CWM is require to flash modern ROMs
  • you can apply updates via the revovery mode if you have already updated it.
  • the kernel gets replace usually with new roms
  • once the dodgy kerenel is replace the brick bug should no longer be an issue
  • this is a non brick bug rom - http://forum.xda-developers.com/showthread.php?t=1555259
  • the cynogenmod does not have GAAPS installed, you have to download them seperate at 96mb

  • files for flashing can be 1 or 3 files. in either case these files will be tar files.
  • for flashing put the phone in download mode, make sure kies is not running
    • if one files, which is a tar, place this in the pda slot see picture
    • if 3 files, which are tar put them in like in the picture
    • then if backup all done, hit flash, this is it

  • wipe custom rom couter and yellow triangle with jig
  • you can flash individual sections ie kernel, csc etc..
  • flashing a full stock rom does not seem to wipe data or super root
  • an insecure kernel is only required once to make the rom rooted
  • factory reset (from off, vol up + home + pwr) gets you into hidden menus which icludes wipe all user data, this wipes all stored programs and user data
  • download mode (from off, vol dwn + home + pwr)
  • S2 Root v1.1 - For Samsung Galaxy S II is simple! Flash insecure kernel then run S2 Root and Press Root Device. My Root method only roots the device and installs busybox. Chainfires method also installs Clockworkmod Recovery.
  • to wipe counter and triangle using jig, power phone of and plug it in until it says complete
  • cwm = Clockworkmod Recovery, ClockworkMod – also known as Clockwork and CWM
  • What Is ClockworkMod Recovery And How To Use It On Android [Complete Guide]
  • odin is samsungs own flashing program

  • Factory/Hard Reset:
    • Recovery mode - Turn phone off, press and hold Vol Up + Home + Power. The Volume keys navigate the menus and Home actions your choice
    • Dialer - enter *2767*3855#
    • Accessing through menu - Settings - Privacy - Factory data reset.
Published in Android
Saturday, 21 February 2015 19:54

My Xampp Performance Notes

Update (22-01-17) - The following settings work

The main cause for slow xampp on windows is the MySQL service and the slow access times slow the whole page loading process.

i used the MySQL ini file my-huge.ini and these settings from the drupal site both the PHP and innodb. Other settings might of been applied at testing but I dont think so.

INNODB SPECIFIC

innodb_buffer_pool_size = 384M
innodb_additional_mem_pool_size = 20M
innodb_log_file_size = 10M
innodb_log_buffer_size = 64M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 180


Primary Document

Preface

The document covers how to improve speed in Xampp as I have found it struggles to most basic tasks quickly.

Xampp is easily configurable and that is why I have persevered with it and created this document in which my research has been successful.

I will cover all of the tips and settings that I discovered along the way. Some are of use whilst others were and some definitely not.

There are 2 main areas where xampp can be slow.

  1. http daemon – rendering of the html
  2. MySQL Daemon – the actual retrieval of the data

General

When to diagnose xampp speed

  • firefox / ie cache dont let this fool you. there are also several types of FF cache
  • dont forget webserver cache ie htaccess
  • turn all caching off when diagnosing xampp speed

Research:

Localhost

Below are various lines that should be added or commented out in the hosts file to increase the speed a page loads. I have seen various combinations of these.

These localhost settings try them on there own to see if you get any improvements. Most likely on windows 7+ and the latest version of xampp you will see no difference but on old setups (which need updating) you might see some benefit.

127.0.0.1 127.0.0.1

  • Add to localhost
  • this one is probably bollocks because of an infinite loop or pointless lookup

127.0.0.1 locahost

  • comment out
  • if this is commented out, localhost will not be resolved
  • Win7 ultimate x64 this is commented out by default. Xampp MySQL resolution will not work without this statement (tested on v1.8.3.0)

::1

  • comment out
  • possible use to have some effect in vista where the IPV6 method was not implemented correctely, it certainly does stop the IPV6 lookup happening before the IPV4 so will save a little time there and any possible issues with IPV6 from xampp. Do not permanently change this unless you see a marked difference. In windows 7+ these issues are probably resolved and also in later version of xampp where the network stack is a lot better and compiled with newer more compatable binaries.
  • NB: If you comment out ::1 when you ping localhost locally you will receive a ping back from 127.0.0.1, if you do not comment it out you receive a ping back from ::1 (or whatever)

not massive improvements, if any

Research:

Network

Browser

  • network.dns.disableIPv6 (FireFox, IPV6 service)
    http://kb.mozillazine.org/Network.dns.disableIPv6
  • network.http.keep-alive - toggle it to false (default/integer/115) ? (FireFox)
  • Use browser with no addons
  • Accessing the website via the IP i.e. 127.0.0.01 can be quicker because there are no DNS lookups

PHP

  • Increase memory_limit from (i.e. 64mb to 256mb), read this
  • disable xebug - http://stackoverflow.com/questions/1891031/xampp-on-win7-too-slow
  • eAccelerator – this will speed things up but not the underlying system which is what I am addressing in this document.
    uncomment zend_extension = "C:\xampp\php\ext\php_eaccelerator_ts.dll" - http://stackoverflow.com/questions/1891031/xampp-on-win7-too-slow

    eAccelerator is a free open-source PHP accelerator & optimizer. It increases the performance of PHP scripts by caching them in their compiled state, so that the overhead of compiling is almost completely eliminated. It also optimizes scripts to speed up their execution. eAccelerator typically reduces server load and increases the speed of your PHP code by 1-10 times.

MySQL

  • innodb_flush_log_at_trx_commit = 2 (some say option 1 can be quicker) (already set to 1, does not seem to make that much difference)
  • realpath_cache_size = 24mb (small increase so far)
  • MyISLAM vs INNODB
  • MySQL to use MyISAM
  • MySQL caching (query cache)
  • MySQL settings
  • Innodb settings all described in “my-innodb-heavy-4G.ini”
  • Address individual settings + add links
  • innodb_buffer_pool_size ?
  • innodb_flush_log_at_trx_commit = 2 (definately quicker)

Example 1from here

The query side of things is not 100% needed because it will not effectively affect the base line speed.

#----------------------------------------------------
#          !!!! Query Cache Config !!!!
#----------------------------------------------------

query-cache-size = 524288000
query-cache-limit = 5242880
query-cache-type = 1

#----------------------------------------------------
#          !!!! InnoDB Buffer Config !!!!
#----------------------------------------------------

innodb-buffer-pool-size = 1000M
innodb-additional-mem-pool-size = 200M
innodb-log-files-in-group = 2
innodb-log-buffer-size = 10M
innodb-file-per-table = 1

Example 2from here

innodb_buffer_pool_size = 1G
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency=8
transaction-isolation=READ-COMMITTED

Research:

people have said moving back to myislam over innodb make a massive difference.

here is why.

all the data from all the databases in xampp is stored in 1 files but has table referecnes for compatability only. so what this means if you have one nasty database it will slow them all down because you have to parse the whole database. by switching back to myislam they all have their own separate files and so will not affect each other.

This article includes discussion on the following from running slow on localhost

  • realpath_cache_size = 24mb
  • MySQL to use MyISAM
  • innodb_buffer_pool_size ?
  • innodb_flush_log_at_trx_commit = 2
  • innodb-file-per-table = 1   (this setting create 1 file per database instead of all in one)

This article includes discussion on the following from localhost (xampp) very slow on Vista for some reason

  • call the apache web server address not by hostname but ip address. On a local computer it is 127.0.0.1
  • the other solution is to disable TCP/IP v6 protocol of your network interface
    add v6tov4 listenport=80 connectport=80

General Links:

Conclusion

There might be specific issues on certain systems but the majority of the lag is with the MySQL engine, the database settings, especially since xampp is now using INNODB instead of the old MyISLAM.

Stay with INNODB as it has better data protection. It is best to tweak the settings to get the best out of INNODB rather than migrate to MyISLAM.

Current at (29-06-13) and (WIP)

innodb_buffer_pool_size = 1G  (has biggest effect)
innodb_additional_mem_pool_size = 200M
innodb_flush_log_at_trx_commit = 2
innodb_thread_concurrency = 8
transaction-isolation = READ-COMMITTED

these are commented out in hosts but probably make no difference on modern systems

#             127.0.0.1 127.0.0.1
#             ::1       localhost

NB:

  • A faster computer with more RAM and faster disk will always make xampp run quicker.
  • This was in some of my notes and might need changing,
    ## Set .._log_file_size to 25 % of buffer pool size
    innodb_log_file_size = 256M

Real Life Example - httpd performance and Conclusion

On A fresh Windows 7 Installation

  • i do not need to add '127.0.0.1 localhost' rule in hosts file. it works as is.
  • httpd.exe also works a lot quicker
  • httpd.exe still maxes out but for 1/10 of the time, therefore indocating something on the tcp/ip stack is interfereing
  • firefox and ie on the faulty system do not have smooth browsing experiences and can crash frequently
  • xampp should works without a modicifaction to the host file indicating an issue with the microsoft dns service
  • when zone alarm was installed the ping response form 127.0.0.1 would get slower and slower whereas a ping to ::1 would always be <1ms

Load times on the fresh copy windows 7, using a large website with xampp and on a 5400rpm drive:

Page		afterdispatch (no internet)	afterdispatch ( with internet)

home		546ms				210ms
portfolio	327ms				176ms

Causes of Slowness:

  • dodgy 3rd party program still installed that integrate/interfere witht the tcp/ip stack
  • dodgy registry entry
  • corrupt windows system files (not likely as sfc found no errors)
  • remanents of a program left installed that integrate/interfere witht the tcp/ip stack

Solution Options

  • find the offending software (not easy and have already tried)
  • fresh install of windows 7 (when installing new software monitor with a set benchmark, ie a slow website in xampp)

What Did I Do ?

I reformatted my pc in the end because there was something affecting the tcp/ip stack

How do i know it was the TCP/IP stack

  • xampp would not work unless i put in a host file entry localhost 127.0.0.1
  • when zone alarm was installed over time the ipv4 ping got slower whilst the ipv6 stayed the same
  • browsing could be jerky. on a fast internet connection it still did not seem as fast as other peoples
  • i ran a copy of large website on a fresh windows 7 install on a 5400rpm drive and a page after dispatch came in about 300ms where as my dodgy wiondows could be as long as 3000ms just for the dispatch
  • all my speed modifications never made that much difference to xampp performance (perhaps the innodb settings and php memory increase, ipv4 default showed promise but that might be because of the underlying tcp/ip stack issue i had)

Performance Notes (to be sorted)

Worked

  • disabled ZA antivirus and firewall - makes a big difference
  • I just changed the server name from localhost to 127.0.0.1 in database connection configuration and it worked light speed.
    (http://stackoverflow.com/questions/13248260/localhost-taking-too-long-what-to-do )
  • add xampp to AV/malware realtime scanner exclusions
  • disabling malware bytes definately makes a performance increase, you can hear the HDD access is a lot more vigourous.
  • malware bytes and comodo AV might not like each others realtime scanner running at the sametime
  • make sure any xammp log file is not more that a couple of megs big
  • comodo AV pipes up when you do a page refesh in a browser of an xammp server site (very heavy cpu usage)
  • with hips/firewall/av all disabled 'internet sercurity helper' (comodo) service still runs at high CPU. xammp a little quicker
  • increasing PHP Memory can improve performance (but this is an indirect affect because it makes PHP run better not xampp)
  • in a multicore processor, enabling the CPU to run as a single processor as xampp is not multicore aware

Didn’t Work

  • revert using 127.0.0.1 in joomla databse connection - makes no difference
  • re-enable ipv6 on my wifi card - (seems to make no difference)
  • xdebug - already disabled so no difference here.
  • zend_extension = "C:\xampp\php\ext\php_eaccelerator_ts.dll" - already disabled
  • changing port 8080 (prevents conflicts)
  • DefaultReceiveWindow = (10000 * 1024) / 8 = 1280000
    DefaultSendWindow = (10000 * 1024) / 8 = 1280000
    no real difference or worse (need removing)
  • run as administrator

Try

  • http://www.techunboxed.com/2012/08/how-to-disable-ipv6-in-windows-8.html  (also for windows 7)
  • dont foget to make sure FF is not hogging the memwory when testing
  • Disable ipv4 to IPv6 and disable ipV6 as unticking in network card does not do what is expected
  • bind mysql to 127.0.0.1 not localhost
  • running xampp as services
  • use the latest version
  • on laptop make sure computer is set to high performance
  • run xampp in safe mode

My Case where My Stack was faulty

  • if using the default hosts file for windows 7 x64, the mysql database might not connect. you must uncomment. The following line allows a IPv4 lookup with out going through the windows IPv6 to IPv4 converter.
     #       127.0.0.1       localhost

    Certain versions fo mysql binaries do not support IPv6 and how they lookup localhost can cause issues. if you uncomment the following line in the host file, this prevents mysql connection because it forces ‘localhost’ lookup on IPv6
     #       ::1             localhost
  • mysql 5 does not handle IPv6 - http://bobstrand.com/totm/2010/04/hey-dude-wheres-my-localhost/
  • I applied fixit that prefers IPv4 over IPv6, rebooted - definitely better, but i need to test longer

xampp mysql/mysql in general cannot handle ipv6

xampp mysql/mysql in general cannot handle ipv6. if it resolves localhost and gets ::1 , the mysql cannot resolve the address and thus does not work

solutions:

  • add to host file, localhost 127.0.0.1 (this on its own will fix the resolution but not the speed issue)
  • make ipv4 prefered protocol (this on its own will fix the resolution but maybe not the speed issue as overtime ipv4 ping to localhost etc.. gets longer. but at the beginning there is a definate speed improvement)
  • disable ipv6 completely (this on its own will fix the resolution and probably the speed issue permanently)

unchecked:

  • bind mysql to 127.0.0.1   (this on its own will fix the resolution but maybe not the speed issue)
  • it must be it does not like ::1 return instead of 127.0.0.1

Links

Useful

Ping Batch File

This batch file will allows you to ping the different types of network hosts. Run this and view all of the ping responses on the screen at the same time. I would then monitor them over time. I ran a test for 32 hours to make sure I could see any differences easily.

start ping localhost -t
start ping 127.0.0.1 -t
start ping 192.168.1.100 -t
start ping ::1 –t

IP Performance Notes

Microsoft IP Fixits

These are useful for helping with IPv4 and IPv6 issues

  • MicrosoftFixit50267 - restore default hosts file.msi
  • MicrosoftFixit50409 - disable IPv6.msi
  • MicrosoftFixit50410 - Prefer IPv4 over IPv6 .msi

Why is my CPU load for Apache almost 99%?

This just something that i have picked up but not checked.

There is one of two scenarios at play here. Either your CPU is maxing out, or you can browser connect to the server, but not see anything (the system is trying unsucessfully to load the page). In either case you can find the following message in the Apache log file:

Child: Encountered too many AcceptEx faults accepting client connections. winnt_mpm: falling back to 'AcceptFilter none'.

The MPM falls back to a safer implementation, but some client requests were not processed correctly. In order to avoid this error, use "AcceptFilter" with accept filter "none" in the "\xampp\apache\conf\extra\httpd-mpm.conf" file.

Published in xampp
Page 49 of 96