This article aims to explain how to develop a server using Joomla! Platform . It is not the author's intention is to explain that Joomla! Platform so that needs some extra information that is Joomla! Platform visit http://docs.joomla.org/Platform/11.1
Introduction to JSockets
To write a server developed in PHP and using Joomla! Platform as a structure you need to have knowledge of programming using sockets. These objects are not included in the official version of Joomla! Platform, so I created a new library for Joomla! Platform including configuration and management of sockets.
These libraries can be downloaded from the fork that I created in my GitHub account: https://github.com/fastslack/joomla-platform
To see the sockets files you can go to: https://github.com/fastslack/joomla-platform/tree/staging/libraries/joomla/sockets
Installation of Joomla! Platform with JSockets
mkdir my-server
cd my-server
cp-r .. / joomla-platform / libraries /.
Creating the server object
The file my-server must be in the 'my-server':
<?php
/**
* @version $Id:
* @package Joomla! Platform
* @subpackage myServer
* @copyright Copyright (C) 1996 - 2011 Matware - All rights reserved.
* @author Matias Aguirre
* @email This e-mail address is being protected from spambots. You need JavaScript enabled to view it
* @link http://www.matware.com.ar/
* @license GNU/GPL http://www.gnu.org/licenses/gpl-2.0-standalone.html
*/
define( '_JEXEC', 1 );
include_once ( './libraries/import.php' );
include_once ( JPATH_PLATFORM . '/joomla/sockets/server.php' );
class myServerServer extends JSocketsServer {
/**
* A JCli object for the application to use.
*
* @var JCli
* @since 11.3
*/
protected $cli = null;
/**
* A database object for the application to use.
*
* @var JDatabase
* @since 11.3
*/
protected $dbo = null;
/**
* A database object for the application to use.
*
* @var JDatabase
* @since 11.3
*/
protected $address = '127.0.0.1';
/**
* A database object for the application to use.
*
* @var JDatabase
* @since 11.3
*/
protected $port = 8080;
/**
* Class constructor.
*
* @return void
*
* @since 11.1
*/
public function __construct()
{
// Init cli
jimport( 'joomla.application.cli' );
$this->cli = JCli::getInstance();
// Init database
/*
jimport( 'joomla.database.database' );
$config = array(
'driver' => 'mysqli',
'host' => 'localhost',
'user' => 'USERNAME',
'password' => 'PASSWORD',
'database' => 'DB',
'prefix' => 'jos_',
);
$this->dbo = JDatabase::getInstance($config);
*/
// Parent construct
parent::__construct();
// Start server
$msg = "\nWelcome to My Server. \n" .
"To more info, type 'help'.\n";
$this->listen($this->address, $this->port, $msg);
}
/**
* Process the command
* @return bool
*/
protected function __processCommand($childId = 0, $command = false)
{
switch($command) {
case "test":
$this->test($childId);
break;
case "help":
$this->help($childId);
break;
case "quit":
$this->killAll();
die("Kill message received\n");
break;
}
}
/**
* Print the help
*
* @return bool
*/
protected function help($childId)
{
$output = "\nPlease type 'test' for testing...\n";
$this->threads[$childId]->write($output);
}
/**
* Print the test
*
* @return bool
*/
protected function test($childId)
{
$output = "\nThis is a test server...\n";
$this->threads[$childId]->write($output);
}
}
$myServer = new myServerServer();
?>
Running the server
Now the only thing left for us to do is run the server to start the whole process. To do this we need to give the necessary permissions to the file my-server and execute it:
./my-server
Testing the connection
To test the conection we need to call 'telnet':
This command should return 'Welcome to My Server'
Have fun!