“Allowed memory size of 134217728 bytes exhausted”
I encountered this problem a few times, and setting memory_limit to a higher value didn’t seem to work
Recently I came across a very strange behaviour in a regular expression I wrote years ago.
The webserver upgraded to PHP 5.3.3 and it suddenly stopped working.
Case as follows: I use PHP to read a text-file and with the aid of PCRE (preg_match & preg_split) I look for certain matches in that text-file. The program splits different paragraphs into seperate records. But suddenly preg_split stopped working:
Curious thing: previous and newer versions of PHP (e.g. 5.3.8 in a XAMPP test environment) did not require to look for possible occurrences of carriage returns (\r).
Sometimes you want to output HTML to the browser before a script has finished completely. In some browsers it takes a while before ‘some’ content is displayed. Flush buffers can help to actively force output to be shown.
A combination of PHP functions is useful to please all kinds of browsers. However the code below might no longer work in recent Apache/PHP environments. Still works locally on XAMPP
function flush_buffers(){
ob_end_flush();
ob_flush();
flush();
ob_start();
}
ob_implicit_flush(1);
for($i=0; $i<10; $i++){
echo $i;
//this is for the buffer achieve the minimum size in order to flush data
echo str_repeat(' ',1024*64);
sleep(1);
}
Om lokaal wat programmeerwerk als voorbereiding op een live omgeving te verrichten, is XAMPP de ideale omgeving. XAMPP komt pas echt tot zijn recht met de opstelling van een eigen mailserver (Mercury Mail) waarmee je lokaal het verzenden van mails kan testen.
De uitgebreide versie van XAMPP bevat zo’n SMTP service. Bij een eerste kennismaking word je overstelpt door een hele reeks vensters die kris kras op het scherm staan. Om hierin wat wegwijs te raken, is er een uitstekende videotutorial op YouTube:
Een van de belangrijkste zaken die je moet weten bij dit programma is dat voor quasi elke aanpassing het programma opnieuw moet opstarten omdat Mercury Mail in XAMPP geen service is!
De basisinstellingen
Configuration: volgende protocul modules aanvinken:
Mercury S SMTP server
Mercury P POP3 server
Mercury E, SMTP end to end client delivery client
Mercury D Distributing POP3 client,
Mercury I Iamp4 server
Configuration
Core module
Local domains > add local domain
Localhost
mydomain.com
Configuration
Mercury S
Connection control
Uncheck “do not permit SMTP relaying of non-local mail”
Configuration
Mercury E
DNS Servers (open DNS): 208.67.222.222,208.67.220.220
Configuration
Manage local users: een testgebruik definiëren
Het is best dat je geen gebruik maakt van postmaster@localhost, omdat deze standaard alle foutberichten opvangt.
Username: root
Personal name: root
Password: pass
Het enige wat je nu nog moet doen is de configuratie van deze local mail account in je favoriete e-mailprogramma. Daarin volg je dezelfde werkwijze alsof je een remote mailserver zou aanspreken, maar bij de serversettings plaats je gewoon ‘localhost’.
De vooraf gedefinieerde accounts hebben volgende paswoorden:
The best practice when storing data in a database is to store it in its most purest form.
When allowing users to edit data through HTML webpages you need to encode some characters so your HTML-forms won’t break. You can do this by using htmlspecialchars (or htmlentities). Below is an example with htmlspecialchars where only the double quotes are escaped (ENT_COMPAT flag).
Mind the accept-charset in the form value: I try to work with UTF-8 and UTF-8 only. (see your collation in mySQL is also set to UTF-8!)
You can run this on code on localhost (e.g. XAMPP)
<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>htmlspecialchars (utf-8 encoding)</title>
</head>
<body>
<h1>htmlspecialchars (utf-8 encoding)</h1>
<h2>Before form post</h2>
<?php
$dbvalue = "String: ? < > ' - \" `´& % ‰ € ® 2011";
$formvalue = htmlspecialchars($dbvalue, ENT_COMPAT,"UTF-8");
?>
<p><strong>String</strong> is a value coming from a database record in its cleanest form: <span style="color:green;"><?php echo htmlspecialchars($dbvalue); ?></span> </p>
<p>For use in a text form, especially the double quotes, must be encoded so the <em>value=""</em> doesn't break. We use <strong>htmlspecialchars</strong> (ENT_COMPAT) function. ENT COMPAT only forces double quotes to be changed into &quot; (besides < > ? &)</p>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" accept-charset="UTF-8">
<label>String:
<input name="string" type="text" value="<?php echo $formvalue; ?>" size="50" /></label>
<br />
The value of title inside this form looks like <span style="color:red;"><?php echo htmlspecialchars($formvalue); ?></span><br />
<input name="submit" type="submit" value="submit this form" />
</form>
<?php if($_POST){ ?>
<h2>Yes, the form was posted</h2>
<p>When the form is <strong>submitted</strong>, the <strong>string</strong> field will again have a value in its purest form (no &quot; values but ") (not the htmlspecialchars formatting)</p>
<p><strong>String</strong> has submitted value: <span style="color:green;">
<?php echo $_POST['string']; ?>
</span></p>
<?php } ?>
</body>
</html>