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
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() ?>
http://www.example.com/grab.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;
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;
}
This code allows you to stretch background images when you page expands to provide a better user experience.
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"> </td>
</tr>
<tr>
<td class="top"> </td>
<td> </td>
</tr>
<tr>
<td class="middle"><img src="/middle.jpg" alt="background image" id="bg" /></td>
<td> </td>
</tr>
<tr>
<td class="bottom" colspan="2"> </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
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:
; Magic quotes for incoming GET/POST/Cookie data.To
magic_quotes_gpc = On
; Magic quotes for incoming GET/POST/Cookie data.
magic_quotes_gpc = Off
<IfModule mod_suphp.c>
suPHP_ConfigPath /home/example/public_html
<Files php.ini>
order allow,deny
deny from all
</Files>
</IfModule>
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.
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.
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.
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.
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>
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.
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.
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.
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 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/
Does the following
Notes
Android 5.1.1 on Samsung S2 Links
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.
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.
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.
After days of research I did the following to get my SD Cards to work
External SD Card (sdcard1)
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
These are my notes on all of the googleing and trying of different solutions
The terminal is a powerful tool to be able to help diagnose partion and disk issues
** add websites where appropriate to my links directory
My Samsung was already rooted so if yours is skip to the next section………
{Picture of odin here}
In the picture you can see the ROM is cut up into sections
So I Flashed by
Files I used for a successful flash
My Phone was already Rooted
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
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.
When to diagnose xampp speed
Research:
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
127.0.0.1 locahost
::1
not massive improvements, if any
Research:
Example 1 – from 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 2 – from 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
This article includes discussion on the following from localhost (xampp) very slow on Vista for some reason
General Links:
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:
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
I reformatted my pc in the end because there was something affecting the tcp/ip stack
# 127.0.0.1 localhost
# ::1 localhost
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:
unchecked:
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
These are useful for helping with IPv4 and IPv6 issues
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.