Setting up PEAR mail on Scotch Box

You have Vagrant and Scotch Box installed. You still need to install Pear.

$ vagrant ssh
$ sudo apt-get -y install php-pear
$ sudo pear install mail_mime

In your PHP script

include_once('Mail.php');
include_once('Mail/mime.php');

Parameters to define SMTP Scotch Box

$params["host"] = "127.0.0.1";
$params["port"] = 1025;
$params["Date"] = date('r',time());
$mail = Mail::factory("smtp",$params);
...

Catch mails in Mailhog at http://192.168.33.10:8025

PHP UTF8 test-template (jQuery, Bootstrap)

This is just a webdevelopment template for PHP (all errors, xdebug), HTML, jQuery, Bootstrap (UTF8 encoding).

<?php
ini_set('display_errors' , 'On');
error_reporting(E_ALL);
session_start();
header("Content-Type:text/html;charset=utf-8");
ini_set('xdebug.var_display_max_depth', -1);
ini_set('xdebug.var_display_max_children', -1);
ini_set('xdebug.var_display_max_data', -1);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>...</title>
<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

</head>
<body>

</body>
</html>

PHP long running script without Ajax

<?php
header("Content-Type:text/html;charset=utf-8");
session_start();
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"  content="text/html; charset=utf-8" />
</head>
<body>
<?php

$executiontime = 5; // max time for scripting
$sleeptime = 3; // seconds to pauze after execution time limit


if(!isset($_GET["continue"])){

	$_SESSION["numbers"] = range(1,100000);
	$_SESSION["genesis"] = microtime(true); // absolute start time
	echo count($_SESSION["numbers"]);

}

$_SESSION["starttime"] = microtime(true); // 'this round' start time

foreach($_SESSION["numbers"] as $key=>$value){

		sleep(1);
		// abort and 'reload' upon exceeding execution time
		if((microtime(true) - $_SESSION["starttime"]) > $executiontime){
			echo "<p>" . count($_SESSION["numbers"]) . " items left";			
			echo "<br>This round: " . round((microtime(true) - $_SESSION["starttime"]),2) . " seconds";		
			echo "<br>Total time: " . round((microtime(true) - $_SESSION["genesis"])/60,2) . " minutes";
			echo "<p><strong>Pause script...</strong> Resume in $sleeptime seconds...</p>";
			die ('<meta http-equiv="refresh" content="'.$sleeptime.';URL='.$_SERVER['SCRIPT_URI'].'?continue=1" /></body></html>');
		}
		
		// do some stuff while execution time is still ok
	
		unset($_SESSION["numbers"][$key]);
}

echo "<br>Completed...: total time " . round((microtime(true) - $_SESSION["genesis"])/60,2) . " minutes";