Archive for the ‘php’ Category

PHP im Hintergrund (fork)

Tuesday, August 16th, 2011

Ja, man kann PHP als Hintergrundprozess, unabhängig vom Browser laufen lassen.

Der Browser macht einen Request. Der Server liefert eine Response, die der Browser anzeigt. Der Server startet zusätzlich einen http-Request im Hintergrund, der unabhängig vom Browser weiterläuft. Wenn der Browser den Request beendet (Stopp-Button), dann läuft der Hintergrundprozess trotzdem weiter.

Hauptscript vom Browser aufgerufen, php_fork_main.php:

echo "<p>start\n";
echo "<p>calling background process\n";
##############################################################
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, 'http://localhost/php_fork_background.php');
curl_setopt ($ch, CURLOPT_TIMEOUT, 1);
curl_setopt ($ch, CURLOPT_POST, false);
curl_setopt ($ch, CURLOPT_FRESH_CONNECT, true);
curl_exec ($ch);
curl_close($ch);
##############################################################
echo "<p>background process called\n";
echo "<p>end.\n";

Hintergrundscript, php_fork_background.php:

ob_end_clean();
header("Connection: close\r\n");
header("Content-Encoding: none\r\n");
ignore_user_abort(true); // optional
set_time_limit(0); // run script until it finish
ob_start();
echo ('<p>Text from background process starting');
$size = ob_get_length();
header("Content-Length: $size");
ob_end_flush();     // Strange behaviour, will not work
flush();            // Unless both are called !
ob_end_clean();

#####################################
# background task
#####################################
echo "<p>background process running, this output is not visible";
for($i=0; $i<10; $i++) {
	$data = date("H:i:s") . " - $i\n";
	file_put_contents('fork_background.log', $data, FILE_APPEND);
	sleep(10);
}

Mit dank an http://www.ivankristianto.com/….

Sammlung interessanter Captchas

Thursday, April 28th, 2011

Eine Sammlung interessanter Captchas:

http://www.script-tutorials.com/top10-really-user-friendly-captchas/

Amazon Cloudfront Private Streaming Example

Wednesday, April 7th, 2010

Amazon Cloudfront streaming servers with private URLs have just been online for a few weeks. Therefore there is not much information available nor are there many code examples.

Here are a few links to explaining websites and a working PHP code example.

I hope this helps some other developers :-)

Amazon Documentation
Amazon Forum
Cloudberry HowTo
Bucket Explorer HowTo

>>> Download Code Example:
>>> cloudfront_private_streaming_example.zip