Pages: [1]   Go Down
Author Topic: Arduino web server and PHP  (Read 648 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 2
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a quick question,

Has anyone ever managed to get a stand-alone Arduino web server to serve up full PHP pages, or HTML pages that include PHP code.

example:
Code:
<html>
<head></head>
<body>
<?php  
echo "<h1>Hello World</h1>";
?>

<p>That was PHP saying Hello World.</p>
</body>
</html>
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sure.  They are just text.

The difficulty is only in the amount of memory available.  With only 2K of RAM you have to keep the text stored somewhere else.  Some people keep it in PROGMEM, others use a SD Card.  The challenge with SD Card is it is cumbersome to transfer segments of the file (much less than 2K) from the SD Card to RAM to the Ethernet controller.

If you need your Arduino to serve up extensive web pages, maybe you need to look at a microprocessor oriented board.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Offline Offline
Jr. Member
**
Karma: 2
Posts: 75
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I meant to ask if PHP scripts could work. Of course basic PHP text will.

For example, this PHP script prints out all files in it's directory.
Code: (files.php)
<?php
// open this directory 
$myDirectory opendir(".");

// get each entry
while($entryName readdir($myDirectory)) {
$dirArray[] = $entryName;

}

// close directory
closedir($myDirectory);

// count elements in array
$indexCount count($dirArray);
Print (
"$indexCount files<br>\n");

// sort 'em
sort($dirArray);

// print 'em
print("<TABLE border=1 cellpadding=5 cellspacing=0 class=whitelinks>\n");
print(
"<TR><TH>Filename</TH><th>Filetype</th><th>Filesize</th></TR>\n");
// loop through the array of files and print them all
for($index=0$index $indexCount$index++) {
        if (
substr("$dirArray[$index]"01) != "."){ // don't list hidden files
print("<TR><TD><a href=\"$dirArray[$index]\">$dirArray[$index]</a></td>");
print("<td>");
print(filetype($dirArray[$index]));
print("</td>");
print("<td>");
print(filesize($dirArray[$index]));
print("</td>");
print("</TR>\n");
}
}
print(
"</TABLE>\n");
?>

I know that can be done in the Arduino IDE, but this is about PHP scripts.
Also, the attached screen shot shows how the above code is rendered through an Arduino web server.


* Screenshot99.png (54.66 KB, 758x547 - viewed 24 times.)
Logged

Fort Lauderdale, FL
Offline Offline
Faraday Member
**
Karma: 71
Posts: 6144
Baldengineer
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you're going to find it pretty difficult to write a PHP-interpreter that works in less than 2K of RAM.
Logged

Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.c

Pages: [1]   Go Up
Jump to: