Everyone knows PHP can be used to create websites. But it can also be used to create desktop applications and commandline tools. And now with a class called System_Daemon, you can even create daemons using nothing but PHP. And did I mention it was easy? Update 4 Dec, 2012: Legacy Warning This class was relevant in 2009, and may still be to some people, but if you want to daemonize a php script nowadays, a 5-line Ubuntu upstart script should suffice. If you're still convinced you need to do this with pure PHP, read on. What is a Daemon? A daemon is a Linux program that run in the background, just like a 'Service' on Windows. You reading this page, would not have been possible without them. Why PHP? Most daemons are written in C. Reuse & connect existing code Think of database connections, classes that create customers from your CRM, etc.Deliver new applications very fast PHP has a lot of build in functions that speed up development greatly.Everyone knows PHP (right?) Possible use cases Beta
Transformer un script PHP en Daemon ... - lindev : administration linux , développement php09 fév. 2009 Par Christophe de saint leger le lundi, février 9 2009, 09:32 - PHP - Lien permanent Nous allons voir ici comment faire pour qu'un script PHP puisse devenir un "Daemon" indépendant du navigateur web , personnellement je l'utilise par exemple dans un de mes projets en tant que partie serveur , le script est lancé au démarrage du serveur , puis écoute sur un port donné , pour effectuer une tache précise à la connexion d'un client ... Pré-requis : Pour créer un daemon , nous allons devoir contrôler les processus via la bibliothèque PCNTL de php , pour l'installation , il faut juste compiler PHP avec l'option --enable-pcntl , et surtout , ne pas mettre --disable-cli ni --disable-cgi , car le script qui utilise les fonctions PCNTL , doivent être lancé en CGI , ou CLI , comme expliqué dans la documentation , il vous sera donc impossible de lancer votre script à partir d'un navigateur , sauf si vous utiliser php en mode CGI/FastCGI et non , en module apache . Le principe : L'exemple :
PHP cURL functions tutorialBy jatinder on September 7, 2007 cURL is a library which allows you to connect and communicate to many different types of servers with many different types of protocols. Using cURL you can: Implement payment gateways’ payment notification scripts. PHP cURL library is definitely the odd man out. A typical PHP cURL usage follows the following sequence of steps. curl_init – Initializes the session and returns a cURL handle which can be passed to other cURL functions. curl_opt – This is the main work horse of cURL library. curl_exec – Executes a cURL session. curl_close – Closes the current cURL session. Below are some examples which should make the working of cURL more clearer. Download file or web page using PHP cURL The below piece of PHP code uses cURL to download Google’s RSS feed. As you can see, curl_setopt is the pivot around which the main cURL functionality revolves. cURL functioning is controlled by way of passing predefined options and values to this function.
Caching PHP objects: how to do it in 4 easy steps | <img /> is EverythingThis week, my work for our top secret web app, has mainly revolved around caching. This is work I really enjoy. I can sense the user experience of future customers improving each time I create a useful cache of information that speeds up a page’s load time. Screenshots: Setting remote folder permissions in Transmit (OS X FTP client) How to do it Caching is easy, the way I do may not even be the easiest but here goes: Step 1: Create a readable, writeable, executable folder (folder permissions set to 777) – preferably called ‘cache’ or similar. Step 2: Put this function somewhere that will be called whenever you need to cache something: This returns the time/date minus however many hours you choose. Step 3: Create the actual cache file. /*cache example*/// cache filename variables$cache_filename = 'object_data.inc';$cachefile_full_filename = $_SERVER['DOCUMENT_ROOT'].' This code checks to see if a cache file exists and if it does, whether it’s time stamp is less than an hour old. Step 4: Disclaimer
PHP Class: Porter Stemming Algorithm: chuggnutt.comThe Porter Stemming Algorithm was developed by Martin Porter for reducing English words to their word stems. For example, the word ”connections” would be reduced to its stem form “connect.” This PHP class is a fairly faithful implementation of the algorithm (the web page of which can be found here). The primary use of stemming words is in keyword indexing, if you’re building a search application. Thanks to Mike Boone for finding finding a fatal error in the is_consonant() function dealing with short word stems beginning with “Y”. Additional thanks to Mark Plumbley for finding an additional problem with short words beginning with “Y”—the word “yves” for example. Thanks to Andrew Jeffries for discovering a bug for words beginning with “yy”—this would cause the is_consonant() method checking either of these first “y”s to fall into a recursive infinite loop and crash the program. Yeah, that’s arrogant; allow me some, okay?
An Alternative to Perl: Shell Scripting With PHPAn Alternative to Perl: Shell Scripting With PHP - What are PHP Shell Scripts?(Page 2 of 4 ) Normally shells are interactive, but not always. PHP shell scripts are just like batch files in MS-DOS, but they have more power than the MS-DOS batch file, thanks to PHP. Why Write Shell Scripts? Shell script can take input from a user or file and output them on screenUseful to create your own commands/applicationsDon't have to reinvent the wheelCan be used to automate some day to day tasks, such as backupsGetting StartedLets start with a small script to display the typical "Hello World" text. Open your command prompt change into the folder where PHP is installed and run the following command: php world.php If you're surprised to see the output at the command prompt instead of in a web browser, then welcome to the other dimension of PHP! X-Powered-By: PHP/4.2.3 Content-type: text/html To suppress this HTTP header, we could run PHP with the following command line parameter: php -q world.php