LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-09-2005, 02:09 PM   #16
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38

If you don't have a Linux machine handy, there are versions of the apache web server and php interpreter available for Windows. I have used them to initially develop some web pages before copying them over to a Linux server.

I think that you need to get something that is closer to the actual environment you will be running in. That way the odd behavior quirks that come up can be coded around correctly. I think what you are seeing may be one of those quirks that are particular to the Tulip interpreter.

Sorry, but that is the best that I can come up with at this time.
 
Old 06-10-2005, 07:12 AM   #17
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
Do you have anything specific that you would recommend for me to download to enable me to test the suggestions that you have made and see if I get a different output?
 
Old 06-10-2005, 07:43 AM   #18
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I downloaded the php5 windows binary and I have gotten to the following part of the install guide:

Add the .php extension

For IIS, add it to the Application Mappings.

Start -> Control Panel -> Administrative Tools -> Internet Information Services
Expand your local computer by clicking the +
Right click on Web Sites
Select Properties
Select the Home Directory tab
Press the Configuration button on the lower right side of the screen
Press the Add button
Browse to C:\php
Change Files of type: at the bottom of the screen to Dynamic Link Libraries (*.dll)
Double click on php5isapi.dll or select php5isapi.dll and press Open
Enter .php in the Extension field (be sure to enter the '.' before the php)
Press OK
Press Apply
Press OK
Press OK
Close the Internet Information Services screen

For Abyss,

Declare the interpreter
Open Abyss Web Server's console. In the Hosts table, press Configure in the row corresponding to the host to which you want to add PHP support.
Select Scripting Parameters.
Check Enable Scripts Execution.
Press Add in the Interpreters table.
In the Interpreter field, press Browse..., go to the directory where you have installed PHP and click on php5isapi.dll .
Set Type to PHP Style.
Check Use the associated extensions to automatically update the Script Paths.
Press Add in the Associated Extensions table.
Enter php in the Extension field and press OK.
Press OK
Press Add in the Custom Environment Variables table.
Enter REDIRECT_STATUS (with no leading or trailing spaces) in the Name field and 200 in the Value field and press OK.
Press OK in the Scripting Parameters dialog.
Declare new index files
Select Index Files.
Press Add in the Index Files table.
Enter index.php in the File Name field and press OK.
Apply the modifications
Press Restart to restart the server.


For Apache, in the Apache install folder (C:\Program Files\Apache Group\Apache2 if the default was chosen):
open the conf folder
open the httpd.cnf file with notepad or some other text editor
Add:
LoadModule php5_module "C:/php/php5apache2.dll"
Addtype application/x-httpd-php .php
You may not need to do this step, but if you have a problem running php files you may need to come back and configure the path to php.ini
Search for PHPIniDir and set it to "C:/windows"
If PHPIniDir is not there, you can add it: PHPIniDir "C:/windows" or whatever your windows directory is.
Save the file and restart the Apache server by clicking on the Apache icon in the system tray, moving your cursor over Apache2 and selecting Restart

Which one do I follow here. If apache....do I need to install apache first and if so do you know where I can go to install it?
 
Old 06-10-2005, 08:41 AM   #19
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I also downloaded installed and configured apache but I am error when I try to start apache:

The requested operation failed!

I dont know what or where to go from here. Any ideas?
 
Old 06-10-2005, 10:42 AM   #20
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
I have installed and used a distro called "xampp" for Windows. It was very easy to install and contained all of the components that were needed. Do a google search for xampp and you should come up with a bunch of hits leading to download sites.

Good luck and have fun! (It really is a fairly easy task to perform using this distro)
 
Old 06-10-2005, 11:02 AM   #21
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
Sorry for all of the various posts today. I now have php5 and apache2 web server installed on my pc. I copied my server code to a notepad file and named it Server.php. I saved it to my htdocs folder in apache. When I tried to access the web page via http://localhost/Server.php, The code itself came up..it never executed the code. I thought it may be because i didnt have #!/usr/bin/php -q, but I then got a prompt for me to open the file with notepad. What seems to be the problem?
 
Old 06-10-2005, 11:23 AM   #22
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
It sounds like you don't actually have the php intrepter running in apache. To verify this try the following:

1) Go in to the apache htdocs directory and create a file called "phpinfo.php".

2) Enter the line "<?PHP phpinfo(); ?>" (without the quotes) into the file.

3) Write the file and close it.

4) From your web browser enter "http://127.0.0.1/phpinfo.php" (without the quotes)

Tell me what happens. (If php is running you should get a fairly detailed report of everything that the php intrepter has configured, don't bother telling me this information - I'm more interested in if the page comes up or not at this point)
 
Old 06-10-2005, 12:07 PM   #23
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I again prompted me to open the file with notepad. What do I need to do to get php configured?.....or get my script running?
 
Old 06-10-2005, 12:32 PM   #24
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I was now able to get my script to run finally. However, it does not perform as I expected. Here is how the output looks:

#!/usr/bin/php5 -q Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! Serving Client! socket_read() failed. Reason: Incorrect function.
Coil ID number: 1323857 Coil Width: 37.600 Footage Count: 100 Coil Length: 719
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\CameraServer.php:3) in C:\Program Files\Apache Group\Apache2\htdocs\CameraServer.php on line 87

Now this is the correct information that is being passed, but I am not able to view this until I stop the client from running entirely. I was hoping to be able to run the client and watch the values changing as the different strings are being passed in. How would I implement this?


Also what is the warning about?
 
Old 06-10-2005, 12:41 PM   #25
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
That is why I used the xampp distro. It handled all of this configuration stuff for me. I'm not really sure what all needs to be changed. Looking at my Windows apache/php environment I think you need to modify a file called "httpd.conf". It is the main apache daemon configuration file and on my system/distro resides in "C:\Downloads\xampp\apache\conf\httpd.conf", but do a file find to locate it in your distro. Once you have located the file open it up using notepad. You will need to make changes based upon your own installation. I will give you examples of what my file looks like based on me installing the distro in "C:\Downloads\xampp..."

First, search the config file and determine if you have any entries with the token "php", if so note them and see how they differ with my configuration file.

In a section titled something like "DSO Support" locate and/or add lines like the following (note you will need to modify these lines for your own specific installation, use these as an example only...)

Code:
LoadFile "C:/Downloads/xampp/bin/php4ts.dll"
LoadModule php4_module "C:/Downloads/xampp/apache/bin/php4apache2.dll"
Locate the portion where they are dealing with aliases and locate and/or add the following (same note as above)

Code:
ScriptAlias /php/ "C:/Downloads/xampp/php/"
AddType application/x-httpd-php .php .php4 .php3 .phtml
Action application/x-httpd-php "/php/php.exe"
Alias /phpmyadmin "C:/Downloads/xampp/phpmyadmin/"
    <Directory "C:/Downloads/xampp/phpMyAdmin/>
        Options Indexes MultiViews ExecCGI
        Directory Index index.php
        Order allow,deny
    </Directory>
Locate the portion where they are dealing with the Directory Index and locate and/or add the following (same note as above)

Code:
DirectoryIndex index.html index.htm index.php index.php4 index.php3 index.cgi index.pl index.html.var index.phtml
See if those adding/changing those items work for you. BTW: You will probably need to bring the apache server down and back up again once you have made the changes in order to have apache operate with the new settings.

If this works for you (verify by executing the phpinfo.php script) then cool, you should be okay to test out your own development. If you still fail to execute the phpinfo.php script, then I suggest removing the apache server, php, etc that you have downloaded/installed and obtain/install xampp. It's installation really is easier to get everything configured correctly.
 
Old 06-10-2005, 12:47 PM   #26
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
I just saw you latest post.

It looks like your client is not shutting down the socket after it sends the information. This is preventing the server from catching the read error and terminating the read loop. Simple fix is to do some testing inside of your read loop and if you are sure that you have read in a complete line, then break out of the loop yourself at that time.

As far as the header error is concerned, I am not sure right now. How are you testing your code? Are you using a browser or command line to directly call the php intrepter?
 
Old 06-10-2005, 01:28 PM   #27
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I am using the browser now. I am not sure exactly what you mean about breaking out of the loop. Are your referring to the php server or vb6 client. Also I looked at the conf file and had the following present:

LoadModule php5_module "C:/php/php5apache2.dll"

Addtype application/x-httpd-php .php .php4 .php3 .phtml
ScriptAlias /_php/ "C:/Program Files/PHP/"
Action application/x-httpd-php "/_php/php.exe"

DirectoryIndex index.html index.html.var index.php index.php4 index.php3 index.cgi index.pl index.phtml

All of my Alias directives were commented out.....is that a problem?
 
Old 06-10-2005, 01:37 PM   #28
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Not sure about the aliases being commented out. What happens if you attempt to go to the following URL from your browser:

http://127.0.0.1/phpinfo.php

The loop I was referring to is inside of your php code. You have set up an infinite loop and from within that loop you are attempting to read data from your client via the socket connection. To break out of that loop simply issue the "break;" statement. Although I suggest that you only do this after setting up some tests to make sure you have received all of the data that you need to receive...
 
Old 06-10-2005, 01:45 PM   #29
mrobertson
Member
 
Registered: May 2005
Posts: 275

Original Poster
Rep: Reputation: 30
I got a big report with a bunch of php specs and such just like you said I would. I am just curious why I can not run my script from a web page and be able to sit there and watch the values change. I can not see anything until I shut down my client completely and then the output prints. I even tried commenting out the 2 close statements that I have at the end of my code and it still did not change anything. Is my code wrong? Here is another look at it...maybe something will jump out at you that I am not seeing:




#!/usr/bin/php5 -q

<?php
function giveMeAnArray($delimiter, $string) {
return explode($delimiter, $string);
}

$read_write = "read";

if ($read_write == "read") {
//Initialize the socket
set_time_limit(0);
$address = '127.0.0.1';
$port = 10119;
$counter = 0;
if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {
echo "socket_create() failed. Reason: " . socket_strerror($sock) . "<BR>";
}
if (($ret = socket_bind($sock, $address, $port)) < 0) {
echo "socket_bind() failed. Reason: " . socket_strerror($ret) . "<BR>";
}

//Start listening on the socket
if (($ret = socket_listen($sock, 5)) < 0) {
echo "socket_listen() failed. Reason: " . socket_strerror($ret) . "<BR>";
}

//do {
//Accept an incoming connection
if(($client = socket_accept($sock)) < 0) {
echo "socket_accept() failed. Reason: " . socket_strerror($ret) . "<BR>";
break;
}

do {
//Read whatever was just sent, 1024 bytes' worth. Make this however long you need.
if( false == ($global_string = socket_read($client, 2048))) {
echo "socket_read() failed. Reason: " . socket_strerror($ret) . "<BR>";
break ;
};

if (!$global_string = trim($global_string)) {
continue;
}
else {
print ("Serving Client!<BR>");
}

//Strip whitespace
$global_string = ereg_replace("[ \t\n\r]", "", $global_string).chr(0);

$delim = ',';

$array = giveMeAnArray($delim, $global_string);

$id = $array[0];
$Width = $array[1];
$footagecount = $array[2];
$Length = $array[3];

$counter++;
} while (true);

//Close the connection; Don't leave things like this open...!!
// socket_close($client);
//} while (true);

//Close the socket itself
socket_close($sock);
print("Coil ID number: $id<BR>");
print("Coil Width: $Width<BR>");
print("Footage Count: $footagecount<BR>");
print("Coil Length: $Length<BR>");

header( "Location: http://".$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'] );

} //ends if ("read")
 
Old 06-10-2005, 02:02 PM   #30
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Like I have previously said, you are running an INFINITE LOOP that performs the data reads from your client! Your program won't exit that loop until some sort of error is encountered. Then and only then will your code execute the print statements. By you manually stopping your client, you are generating the action that causes the read to encounter an error, thus breaking out of your infinite loop and doing your printing.

That is exactly why I have been instructing you to add some sort of tests into your infinite read data loop after you receive data from the socket. You need to test how much data you have received and if everything from a single message has been received, then break out of the infinite read data loop.

I am using the term infinite read data loop in an attempt to clarify which loop I am talking about. You program is set up to have two infinite loops. The first one, or outer infinite loop, will be used to cause the program to keep repeating the socket creation, connection, data read, data process, result print, socket close code. In other words, your entire main algorithm. The second loop is your inner loop that performs your infinite read data processing.

The outer loop is controlled by the code starting at the beginning, and running until it hits the header statement. The header statement causes the php source file to be reloaded into the browser and to start running from the beginning.

The inner loop is controlled by your do { } while(true) statements.

Last edited by rstewart; 06-10-2005 at 03:41 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
php server recieving multiple messages mrobertson Programming 6 06-09-2005 12:55 PM
recieving multiple messages with a php server mrobertson Programming 2 06-06-2005 01:01 PM
Receiving Emails through web server? (PHP) gothgeek84 Programming 12 01-16-2005 03:02 PM
Receiving winpopup broadcast messages vrsic Linux - Software 8 10-30-2003 02:31 AM
Slow when receiving pop3 messages Marty McFly Linux - Newbie 1 10-24-2003 01:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration