Announcement

Collapse
No announcement yet.

Server Exchange

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #41
    Thanks again!
    Great links.
    I will definitely study the different scripting languages.
    So post does need one.
    Also sounds like it would be much faster than using cgi.
    I have been using with SQLitening and there is definitely a noticable wait.
    I have a test cgi-bin/subfolder, but didn't give out the link because it wouldn't have shown anything other that it works with "GET".

    I want to make requests like select count(*) from parts;select manuf,redref from parts;
    I have seen lots of references to tcl with Sqlite, but that is another story.


    I will do this tomorrow. I am burned out

    Comment


    • #42
      Playing with the PHP part of this discussion ... shouldn't this simple PHP file ("test.php") echo the first argument in this URL, i.e, echo the string "value1"?

      Code:
      The URL ...
      http://myserver.com/test.php?param1=value1
      ​
      The "test.php" file...
      <!DOCTYPE html>
      <html><body>
      <?php
      echo "Parameter: " . $argv[1];
      ?>
      </body></html>​

      Comment


      • #43
        ... where the "value1" could be the name of file to read and echo the content. or the name of a string to search for in a server database. or just a string value used in the PHP script in any number of ways?

        Comment


        • #44
          This appears to work as I want ...

          Code:
          The URL ....
          http://myserver.com/test.php?param1=value1
          
          The "test.php" file ...
          
          <!DOCTYPE html>
          <html>
          <body>
          
          <?php
          $num = $_GET["param1"];
          echo "Parameter: " . $num;
          ?>
          
          </body>
          </html>​
          When the URL is called, the echo'd response is "Parameter: value1"

          Comment


          • #45
            The point of that PHP test was to do what I asked about in the OP:

            From my PC PBWin app, I want to send a string to a server app, have the server app look up the string in a text database, then return the string and any associated information to my PBWin app. The returned string might be as much as 4K bytes.
            These steps should work ...

            1. Have a simple text file on the server where each line has a unique "key"
            2. The URL sent by the PBWin app looks something like this: http://myserver.com/test.php?param1=keystring
            3. Have a PHP file that looks up the line in the text file containing the keystring
            4. The PHP file writes the matching string to a file "results.txt"
            5. The PBWin app downloads "results.txt" and reads the content.

            ... but do not have the elegance/simplicity of returning the string directly to the PBWin program. The "echo" step would be left out of the PHP file so that there's nothing returned to force a display in a browser. It also doesn't have any kind of security to speak of, although if the results are not personal data I may not care.

            Still, simplicity is nice. I'll play with it some more.

            Comment


            • #46
              <Deleted> Gary found $_GET while I was composing a reply

              Comment


              • #47
                Originally posted by Gary Beene View Post
                4. The PHP file writes the matching string to a file "results.txt"
                5. The PBWin app downloads "results.txt" and reads the content.

                ... but do not have the elegance/simplicity of returning the string directly to the PBWin program. The "echo" step would be left out of the PHP file so that there's nothing returned to force a display in a browser. It also doesn't have any kind of security to speak of, although if the results are not personal data I may not care.
                There shouldn't be any browser involved
                Have you tried post 35. It returns the content of a file directly to the PBWin program using Echo.

                Actually, you don't need to write a file at all. You would just echo the matching string once you have found it. The PBWIn app will get the contents directly in wsDataReturned




                Comment


                • #48
                  Howdy, Stuart!

                  Nope, haven't gotten that far yet. I was just trying to run my idea to the ground before comparing it with the earlier suggestions. I'll spread my vision next! But I'm afraid I've run to the end of my day. This surgery thing doesn't let me play at late as I could before.

                  Thanks, both Mike and Stuart for your comments. I work on this some more tomorrow.

                  Comment


                  • #49
                    Originally posted by Gary Beene View Post
                    The point of that PHP test was to do what I asked about in the OP:
                    These steps should work ...

                    1. Have a simple text file on the server where each line has a unique "key"
                    2. The URL sent by the PBWin app looks something like this: http://myserver.com/test.php?param1=keystring
                    3. Have a PHP file that looks up the line in the text file containing the keystring
                    4. The PHP file writes the matching string to a file "results.txt"
                    5. The PBWin app downloads "results.txt" and reads the content.

                    ... but do not have the elegance/simplicity of returning the string directly to the PBWin program. The "echo" step would be left out of the PHP file so that there's nothing returned to force a display in a browser. It also doesn't have any kind of security to speak of, although if the results are not personal data I may not care.

                    Still, simplicity is nice. I'll play with it some more.
                    This appears to do exactly what you want:

                    Click image for larger version  Name:	result.jpg Views:	0 Size:	7.6 KB ID:	819000

                    Save this are database.txt
                    Code:
                    001:This is the info for key one
                    002:this is the info for key two
                    003:this is the info for key three

                    Save this as argtest3.php
                    Code:
                    <?php
                    if (!(isset($_POST['key'])) ) {
                        die("No file requested");
                    }
                    $key = $_POST['key'];
                    //Get file
                    $filename = 'database.txt';
                    if (! is_readable($filename)) {
                        die($filename." was not found");
                    }
                    $fh = fopen($filename,'r') or die("can't open ".$filename) ;
                    $readtext = fread($fh, filesize($filename));
                    fclose($fh);
                    //find required record
                    $delim = "\r\n";
                    $arr = explode($delim,$readtext);
                    $string = "";
                    foreach ($arr as $line) {
                        if (substr($line,0,3) == $key) {
                            $string = substr($line,4);
                        }    
                    }
                    //Return data
                    echo $string;
                    ?>​
                    Now run this:
                    Code:
                    #COMPILE EXE
                    #DIM ALL
                    #INCLUDE "httprequest.inc"
                    #INCLUDE "ole2utils.inc"
                    
                    FUNCTION PBMAIN()
                     LOCAL wsurl,wsrequest,wsdata,wserror AS WSTRING
                     wsURL      = "https://camcopng.com/argtest3.php" 'change to your URL after you've uploaded the other files and tested with this one
                     wsRequest  = "key=002"
                     wsError    =  PostReq(wsUrl,wsRequest,wsData)
                     IF wsError = "OK" THEN
                      ? wsData,,"GetPost OK"
                     ELSE
                      ? wsError,,"GetPost Error"
                     END IF
                    END FUNCTION
                    
                    FUNCTION PostReq(wsURL AS WSTRING, wsRequest AS WSTRING,wsDataReturned AS WSTRING) AS WSTRING 'returns OK or error message
                         RESET wsDataReturned
                         DIM pHttpReq AS IWinHttpRequest
                         pHttpReq = NEWCOM "WinHttp.WinHttpRequest.5.1"
                         IF ISNOTHING(pHttpReq) THEN
                          ? "WinHttpRequest.5.1 failure",%MB_ICONERROR OR %MB_SYSTEMMODAL,FUNCNAME$
                          EXIT FUNCTION
                         END IF
                        TRY
                           pHttpReq.Open "POST", wsURL, 0
                           pHttpReq.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
                           pHttpReq.Send(wsRequest)
                           LOCAL iSucceeded AS LONG
                           iSucceeded = pHttpReq.WaitForResponse(5) 'added 9/22/22
                           IF pHttpReq.StatusText <> "OK" THEN
                                IF pHttpReq.StatusText = "" THEN
                                    FUNCTION = "No send response"
                                ELSE
                                    FUNCTION = pHttpReq.StatusText
                                END IF
                            ELSE  'success
                                wsDataReturned = pHttpReq.ResponseText
                                FUNCTION = pHttpReq.StatusText
                            END IF
                        CATCH
                            OleShowErrorInfo OBJRESULT
                        END TRY
                     END FUNCTION

                    Comment


                    • #50
                      Howdy, Stuart!

                      Yes, that seems to answer the question for me. Thanks for such a complete response!

                      There shouldn't be any browser involved
                      Well, I had imagined calling the PHP with ShellExecute like this, which does bring up the browser. I'm not sure how to prevent that.

                      Code:
                      Key$ = "ice"
                      URLPath = "http://myserver.com/lookup.php?param1=" + Key$   'PHP uses Key$ to create 'results.txt'
                      hInstance = ShellExecute(0, "Open", URLPath, $Nul, $Nul, %SW_Hide)​
                      ​
                      Your PostReq function avoids that problem. It just seems like there ought to be a shorter/simpler way to activate the PHP file from within a PBWin app?

                      Comment


                      • #51
                        Perhaps I am late to the party....

                        You are "Trying to get the contents of the 47-byte file at https://dotysoftware.com/test.txt​"

                        To me that sounds like you want to open a file, get the contents and do something with the contents, right?

                        Or are you actually wanting to:

                        From my PC PBWin app, I want to send a string to a server app, have the server app look up the string in a text database, then return the string and any associated information to my PBWin app. The returned string might be as much as 4K bytes

                        This sounds like basic client - server stuff, no? Create a server that uses TCPIP to communicate with the clients.

                        I have tons of client server code I can share with you....



                        Comment


                        • #52
                          I think he has a linux server else simple.

                          Comment


                          • #53
                            Originally posted by Mike Doty View Post
                            I think he has a linux server else simple.
                            Correct. See post 15.

                            Dale

                            Comment


                            • #54
                              CentOS had to look it up. Thanks.
                              There is an Apache for Windows (maybe I should try it.) https://httpd.apache.org/docs/2.4/platform/windows.html
                              Now that I have a dedicated server I should act like it.
                              Gary, it is so cool to move or compile a file and it is online.
                              Some day I might even try using the compiler to compile on-the-fly and return a page.

                              Comment


                              • #55
                                At one point I had a Linux server (DNS, Sendmail & Apache), a NT box with proxy and Apache Win, and PCs for 2 boys and myself. The Apache for Windows came with disclaimers that it wasn't "ready for prime time". To me it was more stable than IIS. Should fine for personal use, even if it still comes with warnings. Useful for testing CGI and pages before uploading to ISP's server. Maybe overkill for home, but runs PHP.

                                Boys out of house, downsized to apartment; had to downsize computers too!

                                Cheers,
                                Dale

                                Comment


                                • #56
                                  Originally posted by David Clarke View Post
                                  Perhaps I am late to the party....

                                  You are "Trying to get the contents of the 47-byte file at https://dotysoftware.com/test.txt​"

                                  To me that sounds like you want to open a file, get the contents and do something with the contents, right?

                                  Or are you actually wanting to:

                                  From my PC PBWin app, I want to send a string to a server app, have the server app look up the string in a text database, then return the string and any associated information to my PBWin app. The returned string might be as much as 4K bytes

                                  This sounds like basic client - server stuff, no? Create a server that uses TCPIP to communicate with the clients.

                                  I have tons of client server code I can share with you....
                                  Suggested in Post 9 but subsequently dismissed as not appropriate given the actual situation.

                                  Comment


                                  • #57
                                    Originally posted by Mike Doty View Post
                                    CentOS had to look it up. Thanks.
                                    There is an Apache for Windows (maybe I should try it.) https://httpd.apache.org/docs/2.4/platform/windows.html
                                    If you are setting up a web server you would probably be better off installing a full stack.
                                    Personally I use WAMPServer (Windows/Apache/MySQL/PHP)) https://sourceforge.net/projects/wampserver/

                                    I have it installed on my laptop and use it all the time for this sort of thing.

                                    I have configured a set of virtual hosts with .test names matching my real domains.
                                    Code:
                                    <VirtualHost *:80>
                                    DocumentRoot C:/Wamp64/www/camcopng
                                    ServerName camcopng.test
                                    </VirtualHost>​
                                    etc

                                    i.e. I develop locally usiing http:camcopng.test and when it is all working, I just use WinSCP to copy the files to camcopng.com etc.
                                    (Like many developers, I used to use the TLC .dev, until Google usurped it )

                                    I just checked and it configures CGI by default, so you can use it to test PB CGI applications as well if your hosted server is on WIndows..

                                    Comment


                                    • #58
                                      WampServer runs on Windows and installs all the needed database tools?
                                      https://sourceforge.net/projects/wampserver/

                                      I am reading about it and wondered if your link is better than this one? https://www.wampserver.com/en/downlo...server-64bits/

                                      I am learning a lot this week.

                                      Comment


                                      • #59
                                        Howdy, David!

                                        That database scenario as described in Test Forums is the task of interest. What Stuart posted in Working with Objects appears to do just what I am looking to do and I expect to use his suggestion.

                                        However, I'm still interested in how to use something simpler like ShellExecute (without having a browser appear) to get a PHP file to run on the server. Stuart's PostReq function could be simplified some but an alternate approach to IWinHttpRequest might also be possible. Interestingly, I've seen dozens of posts on the internet asking a similar question but those posts are short on solutions.

                                        Your suggestion about using TCPIP as part of the solution is also of interest. I know too little not to consider any suggestions.

                                        Comment


                                        • #60
                                          What are you going to TCP? Do you have a server?
                                          You might consider using what database you are provided like MySQL.

                                          Comment

                                          Working...
                                          X