Autor Beitrag
bps
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19

Win XP Pro, Debian Sarge
Delphi 2005 Prof., FPC 2.0
BeitragVerfasst: Sa 10.07.04 20:35 
Wie kann ich den PHP-Interpreter in ein Delphi-Programm einbinden?
raziel
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 2453

Arch Linux
JS (WebStorm), C#, C++/CLI, C++ (VS2013)
BeitragVerfasst: Sa 10.07.04 20:37 
Am einfachsten:
Den Interpreter aufrufen und den Output abfangen. Müsste mit Suche in: Delphi-Forum, Delphi-Library DOSCOMMAND eigentlich theoretische funktioneren...


raziel

// edit: bin ich heut wieder schnell 8-)

_________________
JSXGraph
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 11.07.04 08:31 
geht auch praktisch ;-)

_________________
In the beginning was the word.
And the word was content-type: text/plain.
bps Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19

Win XP Pro, Debian Sarge
Delphi 2005 Prof., FPC 2.0
BeitragVerfasst: So 11.07.04 08:45 
Und wie kann ich dem Interpreter Parameter (z.B. von einem HTML-Formular) übergeben?
UC-Chewie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 531

WinXP
D5 Ent
BeitragVerfasst: So 11.07.04 10:32 
Such mal bei einschlägig bekannten Suchmaschinen nach der Funktionsweise von CGI. Über diese Schnittstelle kannst du PHP Variablen mitgeben.

_________________
Egal wie dumm man selbst ist, es gibt immer andere, die noch dümmer sind
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: So 11.07.04 11:29 
was willst du denn überhaupt proggen ?? wie soll das denn arbietn, wenn du fertig bist ?

_________________
In the beginning was the word.
And the word was content-type: text/plain.
bps Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19

Win XP Pro, Debian Sarge
Delphi 2005 Prof., FPC 2.0
BeitragVerfasst: So 11.07.04 13:52 
Ich programmier einen HTTP-Server.
bps Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19

Win XP Pro, Debian Sarge
Delphi 2005 Prof., FPC 2.0
BeitragVerfasst: So 11.07.04 14:05 
In solchen Anleitungen steht nur, wie CGI funktioniert, und nicht, wie man es integriert.

Werden die Parameter dem PHP-Interpreter mittels Programm-Parametern übergeben, oder irgendwie anders?
UC-Chewie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 531

WinXP
D5 Ent
BeitragVerfasst: So 11.07.04 15:26 
CGI ist eine Schnittstelle. Wenn du weißt, wie diese aussieht, dann kannst du dich dran machen, sie zu implementieren.

_________________
Egal wie dumm man selbst ist, es gibt immer andere, die noch dümmer sind
bps Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19

Win XP Pro, Debian Sarge
Delphi 2005 Prof., FPC 2.0
BeitragVerfasst: So 11.07.04 18:00 
Und wie kann ich auf diese Schnittstelle zugreifen?
UC-Chewie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 531

WinXP
D5 Ent
BeitragVerfasst: So 11.07.04 18:39 
Du "greifst" nicht darauf zu, sondern CGI ist ein definiertes Format, in dem festgelegt wird, wie die Daten vom Webserver zum CGI-Programm gereicht werden. In deinem Fall übernimmt dein Programm die Rolle des Webservers und PHP die des CGI-Programms. Nun musst du nachkucken (ich weiß es nicht, sonst würde ich es dir ja sagen), wie die CGI-Schnittstelle (oder meinetwegen das CGI-Format) definiert ist. Z.B. werden einige Dinge als Umgebungsvariablen gesetzt. Das heißt, die GET-Informationen, also das was in der URL hinter dem Fragezeichen steht, schreibst du in eine dem CGI-Format entsprechend benannte Umgebungsvariable rein. PHP holt sich dann diese Variable.
Jetzt musst du nur noch herausfinden, wie diese Variablen genau heißén, was da drin stehen muss oder, falls ich mich mit den Umgebungsvariablen geirrt hab und doch ein anderes Übergabesystem benutzt wird, die Variablen halt entsprechend diesem System übergeben.

_________________
Egal wie dumm man selbst ist, es gibt immer andere, die noch dümmer sind
matze
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 4613
Erhaltene Danke: 24

XP home, prof
Delphi 2009 Prof,
BeitragVerfasst: Mo 12.07.04 18:18 
hmmm.. evtl findest du auch auf der seite von PHP eine beschreibung, wie der interpreter anzusteuern ist

_________________
In the beginning was the word.
And the word was content-type: text/plain.
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: So 22.08.04 12:46 
Nur mal so nebenbei, was meint ihr mit php-Interpreter? Die php-cgi.exe?

Und wie bedient man sie? php-cgi < H:\public_html\test.php und die Ausgabe einlesen?

Wenn das beides stimmt, bleibt nur noch die Frage danach, welche Umgebungsvariablen :!: und wie sich das damit verträgt, dass möglicherweise mehrere php-Scripte gleichzeitig :!: abgearbeitet werden müssen.
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: So 22.08.04 13:10 
achso, und noch etwas:

Ist es legal, dass ich php gleich mit meinem Server-Installationsprogramm mitinstalliere oder muss der es selbst einrichten?

//Edit: Habs eben gefunden beim phpinfo();
localhosts/Tests/info.php hat folgendes geschrieben:
This program is free software; you can redistribute it and/or modify it under the terms of the PHP License as published by the PHP Group and included in the distribution in the file: LICENSE

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

If you did not receive a copy of the PHP license, or have any questions about PHP licensing, please contact license@php.net.


Zuletzt bearbeitet von FAlter am So 22.08.04 14:27, insgesamt 1-mal bearbeitet
UC-Chewie
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 531

WinXP
D5 Ent
BeitragVerfasst: So 22.08.04 13:14 
FAlter hat folgendes geschrieben:
Und wie bedient man sie? php-cgi < H:\public_html\test.php und die Ausgabe einlesen?

So müsste es gehen, ja.

Lies dir mal im PHP-Manual den Abschnitt "PHP auf der Kommandozeile" durch, vielleicht hilft dir das.

_________________
Egal wie dumm man selbst ist, es gibt immer andere, die noch dümmer sind
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: So 22.08.04 14:02 
Ich habe jetzt auch eine Lösung für Parameterübergabe gefunden:

ausblenden Delphi-Quelltext
1:
2:
3:
          GetConsoleOutput('"' + filtxtPHP.Text + '" -f "' + PHP + '" "' +
            ARequestInfo.UnparsedParams + '"', Output,
            Error);


filtxtPHP.Text ist die php-cgi.exe
PHP ist der Dateiname der php-Datei

Die nächste Frage ist jetzt: woher bekomme ich den neuen ContentType?
FAlter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 192

Win XP Home
Turbo Delphi 2006 (Win32), C# (VS 2008 Prof.), Java (Eclipse), PHP
BeitragVerfasst: Mi 25.08.04 18:19 
Falls es jemanden interessiert, hier eine bessere Lösung:

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
function GetConsoleOutput(const Command, Input: String; out Output, Errors: String; const Environment: String): Boolean;
var
  StartupInfo: TStartupInfo;
  ProcessInfo: TProcessInformation;
  SecurityAttr: TSecurityAttributes;
  PipeOutputRead: THandle;
  PipeOutputWrite: THandle;
  PipeInputWrite: THandle;
  PipeInputRead: THandle;
  PipeErrorsRead: THandle;
  PipeErrorsWrite: THandle;
  Succeed: Boolean;
  Buffer: array [0..255] of Char;
  NumberOfBytesRead: DWORD;
  Stream: TMemoryStream;
begin
  Output := '';
  Errors := '';
  //Initialisierung ProcessInfo
  FillChar(ProcessInfo, SizeOf(TProcessInformation), 0);

  //Initialisierung SecurityAttr
  FillChar(SecurityAttr, SizeOf(TSecurityAttributes), 0);
  SecurityAttr.nLength := SizeOf(SecurityAttr);
  SecurityAttr.bInheritHandle := true;
  SecurityAttr.lpSecurityDescriptor := nil;

  //Pipes erzeugen
  CreatePipe(PipeOutputRead, PipeOutputWrite, @SecurityAttr, 0);
  CreatePipe(PipeErrorsRead, PipeErrorsWrite, @SecurityAttr, 0);
  CreatePipe(PipeInputRead, PipeInputWrite, @SecurityAttr, 0);

  WriteFile(PipeInputWrite, Input[1], Length(Input), NumberOfBytesRead, nil);

  //Initialisierung StartupInfo
  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  StartupInfo.cb:=SizeOf(StartupInfo);
  StartupInfo.hStdInput := PipeInputRead;
  StartupInfo.hStdOutput := PipeOutputWrite;
  StartupInfo.hStdError := PipeErrorsWrite;
  StartupInfo.wShowWindow := sw_Hide;
  StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES;

  if  CreateProcess(nil, PChar(command), nil, nil, true,
  CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, PChar(Environment), nil,
  StartupInfo, ProcessInfo) then begin
    result:=true;
    //Write-Pipes schließen
    CloseHandle(PipeOutputWrite);
    CloseHandle(PipeErrorsWrite);
    CloseHandle(PipeInputWrite);
    CloseHandle(PipeInputRead);

    //Ausgabe Read-Pipe auslesen
    Stream := TMemoryStream.Create;
    try
      while true do begin
        succeed := ReadFile(PipeOutputRead, Buffer, 255, NumberOfBytesRead, nil);
        if not succeed then break;
        Stream.Write(Buffer, NumberOfBytesRead);
      end;
      Stream.Position := 0;
      SetLength(Output, Stream.Size);
      if Stream.Size > 0 then
        Stream.Read(Output[1], Stream.Size)
    finally
      Stream.Free;
    end;
    CloseHandle(PipeOutputRead);

    //Fehler Read-Pipe auslesen
    Stream := TMemoryStream.Create;
    try
      while true do begin
        succeed := ReadFile(PipeErrorsRead, Buffer, 255, NumberOfBytesRead, nil);
        if not succeed then break;
        Stream.Write(Buffer, NumberOfBytesRead);
      end;
      Stream.Position := 0;
      SetLength(Errors, Stream.Size);
      if Stream.Size > 0 then
        Stream.Read(Errors[1], Stream.Size)
    finally
      Stream.Free;
    end;
    CloseHandle(PipeErrorsRead);

    WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
    CloseHandle(ProcessInfo.hProcess);
  end
  else begin
    result:=false;
    CloseHandle(PipeOutputRead);
    CloseHandle(PipeOutputWrite);
    CloseHandle(PipeErrorsRead);
    CloseHandle(PipeErrorsWrite);
  end;
end;

//...

    Document := ARequestInfo.Document;
    if Document[Length(Document)] = '/' then
      Document := Document + ExtractFileName(php);

//...

      Environment :=
        'CONTENT_LENGTH='    + IntToStr(Length(ARequestInfo.FormParams)) + #0 +
        'SERVER_SOFTWARE='   + IdHTTPServer.ServerSoftware + #0 +
        'REDIRECT_STATUS='   + 'ALLOWED' + #0 +
        'PATH_TRANSLATED='   + PHP + #0 +
        'QUERY_STRING='      + ARequestInfo.QueryParams + #0 +
        'SERVER_NAME='       + ARequestInfo.Host + #0 +
        'GATEWAY_INTERFACE=' + 'CGI/1.0' + #0 + //oder so ähnlich
        'SERVER_PROTOCOL='   + ARequestInfo.Version + #0 +
        'SERVER_PORT='       + '80' + #0 +
        'REQUEST_METHOD='    + ARequestInfo.Command + #0 +
        //'PATH_INFO='         + ARequestInfo.Document + #0 +
        'SCRIPT_NAME='       + {ARequestInfo.}Document + #0 +
        //'REMOTE_HOST='       + ARequestInfo + #0 +
        'REMOTE_ADDR='       + ARequestInfo.RemoteIP + #0 +
        //'AUTH_TYPE='         + '???' + #0 +
        'REMOTE_USER='       + ARequestInfo.AuthUsername + #0 +
        'HTTP_ACCEPT='       + ARequestInfo.Accept + #0 +
        'HTTP_USER_AGENT='   + ARequestInfo.UserAgent + #0 +
        //'=' + + #0 +
        #0;

      GetConsoleOutput('"' + filtxtPHP.Text + '"' , ARequestInfo.FormParams + #0, Output,
        Error, Environment);


Nur, dass die GetConsoleOutput momentan einen Fehler hat. STDIN wird nicht korrekt umgelenkt... Dadurch funktioniert POST nicht richtig.