Posts Tagged ‘php’

PHP im Hintergrund (fork)

Dienstag, 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/….

Amazon Cloudfront Private Streaming Example

Mittwoch, April 7th, 2010

Update August 2012:
With Amazon servers it is possible to stream videos for Flash and HTML5 video players. So you can view private protected videos on all browsers, mobile phones, ipads and other tablets.
More information: Private Protected Video with Amazon Servers

 

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

UTF8 with PHP and MySQL

Dienstag, Dezember 11th, 2007

There are still a lot of problems when converting a site from latin to UTF8.

Here a some links which describe what has to be done and how:

Unicode Theory:

http://www.joelonsoftware.com/articles/Unicode.html

cheatsheet

http://developer.loftdigital.com/blog/php-utf-8-cheatsheet

unifier

http://www.melody-soft.com/html/unifier.html

MySQL 4.1 und Zeichensätze

http://www.hosteurope.de/faq/index.php?cpid=12229

Using UTF-8 with UltraEdit

http://www.ultraedit.com/index.php?name=Forums&file=viewtopic&t=3511&highlight=unicode

PHP 6/Unicode design document

http://devzone.zend.com/content/summaries/php-unicode-design.txt

Andrei Zmievski’s presentations

http://www.gravitonic.com/talks/

Unicode Consortium reference point

http://www.unicode.org/

The ICU Library at the core of PHP 6

http://www.icu-project.org/

Joel Spolsky’s introduction to Unicode

http://www.joelonsoftware.com/articles/Unicode.html

Handling UTF-8 with PHP

http://www.phpwact.org/php/i18n/utf-8

utf-8-und-die-entity

http://blog.antikoerperchen.de/beitrag/42/utf-8-und-die-entity.html

PHP UTF-8 is a UTF-8 aware library of functions mirroring PHP’s own string functions. Does not require PHP mbstring extension though will use it, if found, for a (small) performance gain.
http://sourceforge.net/projects/phputf8