Types Of Application
There are no any limit but predefined types are:-
App Type |
Run On |
Use For |
BasicApp | Web Server | Design Website, application, api, web service |
Module | Web Server | Integration any other PHP app build with any framework like you can run wordpress in one app and joomla in other app or laravel, Design website, use global environment |
ConsoleApp | Command Terminal | Process System wide execution with no time limit, build system services, desktop applications |
MobileApp | Web Server | Create Hybrid Mobile App |
Multi Process | SphpServer, Web Socket | Same as ConsoleApp + web front end + web socket. Every WS request has separate process and exit on close of WS connection (also wait to finish processing). You can also run child process and integrate any other programming language application like nodejs, python, dot net and create applications that is not possible in php. |
Single Process | SphpServer, Web Socket | Same as Multi Process + only one process for whole server so it is also called native global app. It will start on first request or from console. It wil exit on exit of server or decide by inside code. It will not exit on close of WS connection or browser. Which WS connection start it that is main connection for global app. Main connection use to control the process or watch it. It can build lots of different types of applications that is not possible with php and with web server. Think Chat Server with WS or stream server |
Single Session | SphpServer | Application work only when Manager give permission with login form or any other way. All user share same session. |
WebApp | Web Server | Same as Basic App + AJAX. Easy make gmail type app, cloud app, single page app |
ComboApp | Web Server | Same as WebApp + limit temp file and names + sjs file |
CompApp | Web Server | Create complex component and bind an application object with control. |
There also more like SubApp, ThreeD, GameApp etc. You can build your own type with extend of any above or SphpApp class
Here We will discuss how you can create a hello application in SartajPHP. First Create a new Project with copy of sample folder which located in shared folder to your root directory. Rename sample folder to myproject.
Do Below Step--
- open comp.php file and write code lines :-
$cmpid = "demo";
$cmpname = "SartajPHP Demo";
//database settings default mysql
$duser = "root";
$db = "db1";
$dpass = "mypass";
// if need another database adapter
// file and class name
//$db_engine_path = $libpath . "/lib/Sqlite.php,Sqlite";
//$db = PROJ_PATH . "/db/ideweb.db";
//$db = start_path ."/db/spanel.db";
// 0 mean no debuging and 1 mean less info
$debugmode = 2;
if($basepath != ""){
// comment this line if you are using root folder
$basepath .= "proj_folder/";
}
//app mail settings
$mailServer = "mail.domain.com";
$mailUser = "info@domain.com";
$mailPass = "";
$mailPort = "26";
$masterf = "temp/default/master.php";
$admmasterf = "temp/default/admmaster.php";
function getWelcome(){
$page = SphpBase::page();
switch(SphpBase::page()->getAuthenticateType()){
case "ADMIN":{
$page->forward(getAppURL("admhome",'','',true));
break;
}
case "MEMBER":{
$page->forward(getAppURL("mebhome"));
break;
}
default:{
$page->forward(getAppURL("index"));
break;
}
}
}
Set Shared Library Path in start.php file write code Below
// server side path of res folder, here is parent directory of project folder
$sharedpath = "./vendor/sartajphp/sartajphp";
//$sharedpath = ".";
// browser side url of res folder
$respath = "vendor/sartajphp/sartajphp/res";
//$respath = "./res";
// Slib version server side path ./res/Slib
$slibversion = "Slib";
// lib version server side path ./res/Score/Sphp
// for php 5.6 and 7.1 use Sphp5
// for php 7.4 to 8.2 use Sphp
$libversion = "Sphp";
// not editable start
// <editor-fold defaultstate="collapsed" desc="This is generated code, any changes can effect the application">
if(!defined("start_path")){
define("start_path", __DIR__);
}
if(!isset($argvm) && isset($argv)){
global $argvm;
$argvm = array();
$total = count($argv);
for ($c = 0; $c < $total; $c++) {
$next = $c + 1;
if ($next >= $total) {
$next = $total - 1;
}
if (strpos($argv[$c], "--") !== FALSE) {
if (strpos($argv[$next], "--") !== FALSE) {
$value = "";
$argvm[$argv[$c]] = $value;
} else {
$value = $argv[$next];
$argvm[$argv[$c]] = $value;
$c++;
}
}
}
}
if(isset($argv) && isset($argvm["--sharedpath"])){
chdir(start_path);
$sharedpath = $argvm["--sharedpath"];
$respath = "~rs/res";
}
//$respath = "~up/res/";
$phppath = $sharedpath . "/res";
include_once("{$phppath}/Score/{$libversion}/global/start.php");
$globalapp = startSartajPHPEngine();
// run global app
if($globalapp != ""){
require_once($globalapp);
SphpBase::engine()->execute(true);
}
// </editor-fold>
// not editable end
Create An Application in Apps folder under myproj folder (index.app file) write below code--
// class name should match with file name
class index extends \Sphp\tools\BasicApp{
public function page_new(){
echo "my first application";
}
}
Register this application in reg.php file write below code ---
registerApp("index","apps/index.app");
Check Your Application on url:-- http://localhost/myproj/ with browser View Demo