Remote PHP with PB [Resolved]

Just starting out? Need help? Post your questions and find answers here.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Remote PHP with PB [Resolved]

Post by Kwai chang caine »

Hello at all :D

They are 2 years ago, i need to remote PhantomJS directly, (Sending command, have the answer, sending another time command, have answer, etc..)
And INFRATEC give to me a code for do this 8)
http://www.purebasic.fr/english/viewtop ... 00#p481800

I have try the INFRATEC code with "php.exe" and that not works (No return or crash) :|
Is it possible to remote PHP directly with this code like PhantomJS ?
Have you a better and simple way, for connect PB and PHP together ?

I have also try with Stdin/Stdout like say the php doc, with the "-a" option and nothing, just "Interactive mode enabled" return :|

Code: Select all

Compilateur = RunProgram("E:\PHPPortable\App\Php\php.exe", "-a", "E:\PHPPortable\App\Php\", #PB_Program_Open|#PB_Program_Connect|#PB_Program_Read|#PB_Program_Write)
Sortie$ = ""

Repeat

 Commande$ = InputRequester("Remote PHP", "Entrer your command", "echo 'Hello Kcc';")
 WriteProgramString(Compilateur, Commande$)
 
 If Compilateur 
 
  While ProgramRunning(Compilateur)
  
   If AvailableProgramOutput(Compilateur)
    Sortie$ + ReadProgramString(Compilateur) + Chr(13)
    Debug Sortie$
   EndIf
   
  Wend
 
 EndIf
 
Until Commande$ = "" 

CloseProgram(Compilateur) ; Ferme la connection vers le programme
Have a good day
Last edited by Kwai chang caine on Sat Jan 13, 2018 7:42 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Remote PHP with PB

Post by infratec »

What do you want to do?

php is a script interpreter.
The only thing what php.exe can do directly is executing a script.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Remote PHP with PB

Post by Kwai chang caine »

Hello INFRATEC, happy to talk to you :D

In fact i want do a simple thing, but hard in the same time (mainly for me :oops:)

I want remote it, like you have do for me with PhantomJS
I want have a editgadget for put script and an editgadget for receive the answer, but without create a script file
I want sending directly the script, like it'spossible with the "-r" option

Write the script in the editgadget, push the button, and have the answer of PHP in the editor
Obviously PHP do the job i command to him (createfile, and all the PHP command) but can read the stdout of it

That's works fine with runprogram and read the stdout, but immediately after send the command with "-r" option

Code: Select all

c:\PhpPortable\php.exe -r "echo 'Infratec'"
php terminate :cry:
And i want PHP rest always in live for wait my futur order :D

And i have read, yesterday all the day, and search apparently it's impossible (only with windows) to force php to not terminate :cry:
You can run php in "interactive mode" with windows and more better in "interactive SHELL" in linux
in interactive shell (linux), it's possible to send order to php and have the stdout answer, php wait a new order
But in windows, you run "php.exe" with option "-a" and you have the "interactive MODE" type your script and type CTRL+Z and php execute the script and terminate immedately after...

Then i have read it's possible to communicate with php with PIPE, COM, or may be, other options for communicate between exe, but it's very difficult to me for create this code :oops:

I can also, run cmd.exe who run php.exe and communicate with cmd, but i prefer communicate directly with PHP if it's possible
Your code works with PhamtomJS but crash with php...surely it's not the same mode of communication between PHP and phantomjs...

Thanks to insteresting to my problem
Have a good day 8)
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Remote PHP with PB

Post by infratec »

Short test:

php.exe -a

$a=1;$a = $a + 1; echo $a;

Then press enter.

Nothing with CTRL+Z.
So simply remove all your CRs and at the end send one.
php is still active.
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Remote PHP with PB

Post by infratec »

Short test:

Code: Select all

i = 1

Prog = RunProgram("c:\php\php.exe", "-a", "",#PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Error)
If Prog
  *Buffer = AllocateMemory(1024)
  
  WriteProgramStringN(Prog, "$a=1;$a = $a + 1; echo $a;")
  
  While ProgramRunning(Prog)
     APO = AvailableProgramOutput(Prog)
     If APO
       If ReadProgramData(Prog, *Buffer, APO) = APO
         Res$ = PeekS(*Buffer, APO, #PB_UTF8)
         Debug Res$
         
         i = Val(Res$)
         
         WriteProgramStringN(Prog, "$a=" + Str(i) + ";$a = $a + 1; echo $a;")
         
       EndIf
     EndIf
  Wend
EndIf
Bernd
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Remote PHP with PB

Post by infratec »

Better:

Code: Select all

ReadyFlag = #False

i = 1

Prog = RunProgram("c:\php\php.exe", "-a", "",#PB_Program_Open|#PB_Program_Read|#PB_Program_Write|#PB_Program_Error)
If Prog
  *Buffer = AllocateMemory(1024)
  
  
  
  While ProgramRunning(Prog)
    
    
    APO = AvailableProgramOutput(Prog)
    If APO
      
      If ReadProgramData(Prog, *Buffer, APO) = APO
        Res$ + PeekS(*Buffer, APO, #PB_UTF8)
        
        Debug "Read: " + Res$
        
        If Not ReadyFlag
          
          If FindString(Res$, "shell")
            ReadyFlag = #True
            
            Res$ = ""
            
            Debug "$a = " + Str(i) + "; $a = $a + 1; echo $a; echo 'fin';"
  
            WriteProgramStringN(Prog, "$a = " + Str(i) + "; $a = $a + 1; echo $a; echo 'fin';", #PB_UTF8)
          EndIf
          
        Else
          
          Pos1 = FindString(Res$, "fin")
          If Pos1
            
            While Mid(Res$, Pos1, 1) <> #LF$ And Pos1 <> 0
              Pos1 - 1
            Wend
            
            
            i = Val(Mid(Res$, Pos1 + 1))
            
            
            Res$ = ""
            
            If i = 10
              WriteProgramStringN(Prog, "quit", #PB_UTF8)
            Else
              
              Debug "$a = " + Str(i) + "; $a = $a + 1; echo $a; echo 'fin';"
              
              WriteProgramStringN(Prog, "$a = " + Str(i) + "; $a = $a + 1; echo $a; echo 'fin';", #PB_UTF8)
            EndIf
            
          EndIf
          
        EndIf
        
      EndIf
    EndIf
  Wend
EndIf
Bernd
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Remote PHP with PB

Post by infratec »

But still:

What do you want to do in php which PB can not :?:
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Remote PHP with PB

Post by Kwai chang caine »

Hello INFRATEC,

Excuse me for the late answer, but today i'm on another that yesterday with W10 machine, and this time impossible to run "PHP.exe" :shock: :?
So i have search my old W7 machine for try your code :wink:

Apparently, if your code see the "interactive SHELL enabled " you have the "php.exe" compiled with --with-readline otpion
But on windows, it's impossible to have this option
On windows we have only the "interactive MODE enabled" the interactive SHELL not exist :|

With your code, me i have juste the "interactive MODE enabled" and it's locked :|
What do you want to do in php which PB can no
I want read HTML page with PHP inside and replace the PHP code :wink:
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Remote PHP with PB

Post by infratec »

Hi,

I'm on windows and I compiled nothing.
I simply downloaded the threadsafe window version from here:

http://windows.php.net/download#php-7.2

which is the official site.

A html page with php inside is a simple text file.
So why you don't use PB to replace the php part directly.
It sounds like a simple text replacement.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Remote PHP with PB

Post by Kwai chang caine »

Yes it's an idea, but PHP have thousand of functions and that force me to create a style of "wrapper" for "translate" between PB and PHP :|
Have you see my exemple ? :D
I'm on windows and I compiled nothing.
Incredible, i have not the same behavior than you :shock: :cry:
ImageThe happiness is a road...
Not a destination
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Remote PHP with PB

Post by infratec »

If I download the php version which has an sha256 starting with:
sha256: 6174

Unzip it in an empty directory and call php.exe -a in a cmd window, I get the Interactive shell.


An other idea:

https://xdebug.org/index.php
infratec
Always Here
Always Here
Posts: 6817
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Remote PHP with PB

Post by infratec »

Microsoft Windows [Version 10.0.16299.192]
(c) 2017 Microsoft Corporation. Alle Rechte vorbehalten.

c:\php>php -v
PHP 7.2.1 (cli) (built: Jan 4 2018 04:29:12) ( ZTS MSVC15 (Visual C++ 2017) x86 )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2017 Zend Technologies

c:\php>

c:\php>php -a
Interactive shell

php >
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Remote PHP with PB

Post by Kwai chang caine »

Yeeessss !!!!!
You have right, i have download your version of PHP and it's good an interactive SHELL
I don't know where i have found my portable version :oops:


Image

I don't understand anything
I have read, read read again numerous page web, with this history of "it's impossible to have a shell on windows", and lost one full day fr nothing :?

One thousand of thanks INFRACTEC to have spent your time too, for your idiot fan :oops:
Apparently 1/2 problem resolved...i can talking with PHP now....
Kcc is going to get drunk with PHP's words now :mrgreen: :lol:

I love you !!!

Image

And have a very good week-end
ImageThe happiness is a road...
Not a destination
Post Reply