It is currently Fri Jan 19, 2018 12:56 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: Remote PHP with PB [Resolved]
PostPosted: Thu Jan 11, 2018 10:57 am 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 3993
Location: Lyon - France
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)
viewtopic.php?p=481800#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:
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

_________________
ImageThe happiness is a road...
Not a destination


Last edited by Kwai chang caine on Sat Jan 13, 2018 7:42 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Fri Jan 12, 2018 12:57 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3749
Location: Germany
What do you want to do?

php is a script interpreter.
The only thing what php.exe can do directly is executing a script.


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Fri Jan 12, 2018 1:50 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 3993
Location: Lyon - France
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:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Fri Jan 12, 2018 2:38 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3749
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Fri Jan 12, 2018 2:47 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3749
Location: Germany
Short test:

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Fri Jan 12, 2018 3:16 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3749
Location: Germany
Better:

Code:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Sat Jan 13, 2018 4:31 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3749
Location: Germany
But still:

What do you want to do in php which PB can not :?:


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Sat Jan 13, 2018 5:00 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 3993
Location: Lyon - France
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 :|

Quote:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Sat Jan 13, 2018 6:16 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3749
Location: Germany
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.


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Sat Jan 13, 2018 6:23 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 3993
Location: Lyon - France
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

Quote:
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Sat Jan 13, 2018 6:53 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3749
Location: Germany
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


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Sat Jan 13, 2018 6:55 pm 
Offline
Addict
Addict

Joined: Sun Sep 07, 2008 12:45 pm
Posts: 3749
Location: Germany
Quote:
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 >


Top
 Profile  
Reply with quote  
 Post subject: Re: Remote PHP with PB
PostPosted: Sat Jan 13, 2018 7:40 pm 
Offline
Addict
Addict
User avatar

Joined: Sun Nov 05, 2006 11:42 pm
Posts: 3993
Location: Lyon - France
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye