TOP
SSV Software Systems Register  Register
Log in to check your private messages  Log in to check your private messages
Startseite FAQ Search Mitglieder Profile  Log in 
SSV Support-Forum
PHP nutzen …

 
Post new topic   Reply to topic    SSV-Forum Forum Index >>> IGW/935
<<< Previous topic - Next topic >>>  
Display posts from previous:   
Author Message
kdw



Joined: 05 May 2006
Posts: 1460

PostPosted: 16.05.2013, 10:19    Post subject: PHP nutzen … Reply with quote

Hallo Forum.

Ein IGW/935 besitzt ab Werk eine vorinstallierte PHP-Laufzeitumgebung. Um PHP zu nutzen, muss auf einem externen PC ein PHP-Quellcode in einer Datei gespeichert werden.

Hierzu ein Beispiel: Speichern Sie die folgenden Zeilen PHP-Code auf dem PC in einer Datei mit dem Namen hello.php.

Code:
<?php
echo "Hello, World!\n";
?>


Übertragen Sie diese Datei per FTP vom PC zum IGW/935 in das Verzeichnis /flash. Starten Sie dann dieses PHP-Skript im Rahmen einer Telnet- bzw. SSH-Sitzung einfach durch die Eingabe:

Code:
cd /flash
php hello.php


Das ist schon alles.

Gruß KDW
Back to top
View user's profile Send private message
kdw



Joined: 05 May 2006
Posts: 1460

PostPosted: 29.09.2014, 06:16    Post subject: HTTP REST-Request … Reply with quote

Hallo Forum.

Man kann in PHP auch sehr einfach einen HTTP-REST-Request erzeugen. Speichern Sie den folgenden Code in einer Datei /flash/rest_get_1.php:

Code:
<?php
   
// Create socket ...

if(!($sock = socket_create(AF_INET, SOCK_STREAM, 0)))
{
   $errorcode = socket_last_error();
   $errormsg = socket_strerror($errorcode);     
   die("Couldn't create socket: [$errorcode] $errormsg \n");
}

// Connect socket to remote server ...

if(!socket_connect($sock , '127.0.0.1' , 80))
{
   $errorcode = socket_last_error();
   $errormsg = socket_strerror($errorcode);   
   die("Could not connect: [$errorcode] $errormsg \n");
}

// Send HTTP request to IGW/935 server ...

$message = "GET /fde-http/kwk/Temision HTTP/1.1\r\nHost: 127.0.0.1\r\nConnection: close\r\n\r\n";
if(!socket_send ( $sock , $message , strlen($message) , 0))
{
   $errorcode = socket_last_error();
   $errormsg = socket_strerror($errorcode);   
   die("Could not send data: [$errorcode] $errormsg \n");
}
 
// Receive and print-out the server response ...

if(socket_recv ( $sock , $buf , 2045 , MSG_WAITALL ) === FALSE)
{
   $errorcode = socket_last_error();
   $errormsg = socket_strerror($errorcode);   
   die("Could not receive data: [$errorcode] $errormsg \n");
}
echo $buf;

?>

Bringen Sie den PHP-Code durch die folgende Eingabe zur Ausführung:

Code:
php rest_get_1.php


Sie müssten folgende Aushabe erhalten:

Code:
HTTP/1.1 200 OK
Content-type: text/plain; charset=UTF-8
Cache-Control: no-cache
Connection: close
Transfer-Encoding: chunked
Date: Mon, 29 Sep 2014 05:03:41 GMT
Server: lighttpd/1.4.26

c
556.977684

0


Die Zeichen vor und hinter dem Wert „556.977684“ haben mit dem HTTP chunked response Format der Serverantwort zu tun.

Siehe auch: http://www.binarytides.com/php-socket-programming-tutorial/

Gruß KDW
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    SSV-Forum Forum Index >>> IGW/935 All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
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
You cannot vote in polls in this forum

SSV Software Systems GmbH

Dünenweg 5
30419 Hannover

Fon: +49(0)511  ·  40 000-0
Fax: +49(0)511  ·  40 000-40

sales@ssv-embedded.de


Impressum    ·    Datenschutz    ·    AGB

© 2023 SSV SOFTWARE SYSTEMS GmbH. Alle Rechte vorbehalten.

ISO 9001:2015