0

How I can run MyDaemon.php in background in TideSDK app?

MyDaemon.php - it's my completely ready console software (a lot of code, run other my php scripts, run other software, etc). It's endless php script. It must be start after TideSDK APP and live all time before exit (while user don't close app). TideSDK show status from MyDaemon.php and have few buttons to control it.

Issue 1: How can I start MyDaemon.php in:

Ti.Process.createProcess("?path/to/php/from/tide? -f MyDaemon.php");

What write in "path/to/php/from/tide"? Target computer of my users don't have php package. I want run php from TideSDK like console mode. I include feature PHP and use button "Package with Runtime" in TideSDK Developer. I looked for all files inside TideSDK, but there are nothing like "php" (executing file), only libs.

Issue 2: I try to use

< iframe width=0 height=0 src="MyDaemon.php"></ iframe>

But TideSDK can't start UI APP, because can't take FULL source in frame. MyDaemon.php is undless. How can I include < IFRAME> in ASYNC mode like a real browser?

I try to use this trick:

<iframe width=0 height=0 src="" name="php">< /iframe>
<script>setTimeout("frames.php.location.href=MyDaemon.php", 1000)</ script>

But it's not work too (UI APP started, but halted after execute this frame).

MyDaemon.php can communicate with TideSDK APP any way:

  1. start "/bin/php -f MyDaemon.php" and read/write stdin/stdout. MyDaemon.php can write to stdout any commands in JSON format.
  2. start MyDaemon.php in and write to stdout < script>Ti...[commands]< /script> - any direct JS code for TideSDK
  3. write any msg to file1 and read from file2 (TideSDK will read/write there and execute)
  4. write any msg to SQLite DB (TideSDK will read DB on JS code) Any other way.

It's important: MyDaemon.php want to start in console other php files! Because first process run a lot of childrens for calculating very long tasks. I can ask TideSDK for start this childrens and don't use "exec(/bin/php -f second.php)" in MyDaemon.php.

But I don't want to include double PHP binaries to my APP, because TideSDK APP already have it! It's a lot of extra space in dist.

Thank you and sorry for my language.

adimoise91
  • 558
  • 1
  • 7
  • 26
Dmitry
  • 1

1 Answers1

0

I think you should use Ti.Process.CreateProcess() function, where you can receive the output of the command you are using (I'm using JS syntax for this, not php, so I don't need to include extra libraries to execute commands, or write/read operations)

  • first you have a command cmd or shell command, lets say "ls -la /www"
  • then you need to send all the set of instruction as an array: var cmd = ["ls","-la","/www"]
  • then pass it to a var using Ti.Process.CreateProcess() : var echo = Ti.Process.CreateProcess(cmd);
  • to get the output, you could pipe out the content to another set of instructions.

the final program should look like this:

var cmd = ["ls","-la","/www"];
var echo = Ti.Process.CreateProcess(cmd);
echo.setOnReadLine(function(data) {
    console.log(data);
});

echo.setOnExit(function(data){
    console.log('process ended');
    console.log(data)
});

echo.stdout.attach(echo.stdin);
echo.launch();

Instead console.log, you can pipe out the command output to your div.

also, besides main.html, you cannot load another scripts besides that. TideSDK is not a web based structured platform where you can reach a secondary page inside of the domain accessing it through url (like app://main.html is the only one to be loaded, have tried with no luck to call other "pages"), but instead modularize your app to load elements inside of the main page.

now, creating a daemon is a risk here. You need to be aware that depending on how you refresh the content it could increment severally the CPU usage.

I can suggest you to use a javascript loop to a shell command using the content above written. you do not need a real "daemon" or a secondary script since TideSDK can provide on certain extension that inside TideSDK

Erick
  • 160
  • 8