Announcement

Collapse
No announcement yet.

PowerBASIC and PHP

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

  • PowerBASIC and PHP

    I posted this in another thread and was surprised at the response, so I'm starting a dedicated thread...

    A while back, for my own purposes, I hired a consultant (well-respected on this board) to port some code to PB/Win. The end result is that I have the ability compile PowerBASIC DLLs that work as "php extensions". That means that my web pages can call my DLL's functions with no more php coding than...
    Code:
    <p>
       [b]<?php echo [i]MyPBFunction[/i]('Param1','Param2','Param3',[etc]); ?>[/b]
    </p>
    I have used it with both WIMP and WAMP, and it works like a charm. It works with both PHP4 and PHP5, but it probably requires a Windows web server. (Does anybody know whether or not the *nix flavors of php support Win32 DLLs?) It's different from CGI in that the DLL is always in memory (the web server's memory) so there's no load delay.

    Let me be clear up front, as much as I love this community, this wasn't a trivial project and I'm not likely to donate the code to the public domain. It's more likely to be an addition to my company's "Development Tools" product line, or perhaps another business relationship could be worked out.

    Does this technology sound interesting to anybody else?

    -- Eric Pearson, Perfect Sync, Inc.
    "Not my circus, not my monkeys."

  • #2
    Eric,

    http://marc.info/?l=php-general&m=112959972417466&w=2

    Code:
    w32api_register_function("User32.dll",
                             "MessageBoxA",
                             "long");
    MessageBoxA(NULL,
                "Hello World!",
                "PHP MessageBox",
                0);
    If the Windows DLL's don't work out (and I don't think they will) you can always use FreeBASIC to compile a Linux shared object (.so) to work with php under Linux.

    I'm not sure what your offering? Can you go into more detail?

    John
    Last edited by John Spikowski; 15 Feb 2008, 07:23 AM.

    Comment


    • #3
      John --

      As I understand it, the w32api_register_function is considered "experimental", it works only with early versions of PHP4, it doesn't work at all with PHP5, and it has a reputation for being cranky and somewhat unreliable.

      What I am offering is a way to produce PowerBASIC DLLs that conform with the actual PHP requirements for a genuine PHP Extension. This is not a back-door hack, it is fully compliant with PHP's rules. It interfaces with the php engine in the same way that all Extensions do. Add a line to the php.ini file, and you are off and running.

      It works with all versions of PHP4 and PHP5, and I have not had any problems whatsoever with reliability.

      [Added] Also, I am not using it to pop up message boxes, etc., I am using DLLs to produce html code that is sent directly to the remote browser, via php. I am able to use SQL Tools for database access and Graphics Tools to produce on-the-fly graphics, my own string-parsing library... Lots of stuff.

      -- Eric
      Last edited by Eric Pearson; 15 Feb 2008, 10:12 AM.
      "Not my circus, not my monkeys."

      Comment


      • #4
        Return Values??

        Eric,

        Hummmm ....

        This DOES sound interesting. Can you return values that PHP can use?

        Thanks,
        Mark Strickland, CISSP, CEH
        SimplyBASICsecurity.com

        Comment


        • #5
          Mark --

          Yes, that's exactly what it does. My DLL functions return strings. I'd imagine that it's possible to return numerics as well but I haven't needed them, because all of my logic is encapsulated in PB code, not PHP.

          The functions can accept both php string and php numeric parameters, and there doesn't appear to be a limit to the length of strings that they can return.

          -- Eric
          "Not my circus, not my monkeys."

          Comment


          • #6
            Eric,

            As I posted previously, this is something that I've wanted for a long time. To be honest, I "moved on" from trying to make this work quite some time ago, but as I know I'll be doing more and more with PHP in the future, it is something I would surely purchase.

            And no, *nix servers can't use PB DLL's. BUT, there are still lots of Windows web servers out there, especially in this day of Virtualization.
            Software makes Hardware Happen

            Comment


            • #7
              I Just had a good laugh when i read your "Phone contact" page Eric.

              "There, are you happy?"

              Comment


              • #8
                This sounds like something that could interest me. I have no real experience with things like CGI and PHP, but for some time I've wanted to have something online that taps into my uCalc Fast Math Parser DLL. At its simplest, maybe a user would be able to enter a math expression online, and they would hit Submit and get a result. I figured I could do this with plain CGI (though from your message it seems like it would be faster with PHP since the DLL remains loaded in memory). Facebook seems to use php. I wonder if this might be what allows me to create a Facebook application that uses uCalc (and even on my own site, I'm looking for a more interesting usage of uCalc FMP or Language Builder than merely evaluating a math expression).

                It would be nice if it could return numbers (though it's not essential, since I have a routine that can return the value as a string, as in ucEvalStr("5+4*10") ).

                I couldn't resist visiting your phone contact page based on Elias' last post . While there, I noticed that you have many pages that end with .php. Do those pages on your site have some kind of benefit over ordinary html pages?
                Daniel Corbier
                uCalc Fast Math Parser
                uCalc Language Builder
                sigpic

                Comment


                • #9
                  Daniel,

                  From the little you've said, I can't say that you would "need" PHP for anything you've mentioned. Not to slight Eric's utility, but unless you use PHP, this app won't really help you much. About 95% of my dynamic content is done with plain PB-CGI programs (could be executables, or executables calling DLLs, doesn't matter one bit). However, I often need to support other people's code, done in PHP, so having the ability to combine raw PHP code with my own PB applications (as DLLs) is sure a big advantage.

                  As for PHP "keeping the DLL in memory", this is not a function of PHP, but rather the web server, and its not always a good thing. Some of my servers keep my CGI apps in memory as well, but only under very controlled circumstances and for specific reasons.

                  I also doubt that PB, either as an executable or a DLL, will be much benefit for services such as Facebook. I don't know for sure, but I'm willing to bet big time that they operate on Linux servers. Even if they have Windows based servers, the odds that they'd let you run a compiled app (as a DLL) is slim to none...at best.

                  There really isn't a lot of "magic" to web programming. In fact, its pretty much like anything else except you have a different GUI. You use HTML instead of GRAPHIC etc. The real work is done with a normal PB application which wouldn't look much different from a non-web application save for the difference in output (ie, no direct interface).

                  If you haven't looked over my CGI tutorials, you should take 10 minutes and skim through them. They'll give you a good 10,000 ft. overview and you might be surprised to see how similar things are.

                  As for pages that end in PHP... those are just web pages. You could have an entire site with every page ending in .EXE or .DLL. The end result is exactly the same. PHP, PERL, PB/CC, they all end up spitting out HTML code to your browser. Just take your pick of which language you prefer to use.
                  Software makes Hardware Happen

                  Comment


                  • #10
                    Where can I find your CGI tutorial? (I didn't find it in your tagline link)
                    Daniel Corbier
                    uCalc Fast Math Parser
                    uCalc Language Builder
                    sigpic

                    Comment


                    • #11
                      Daniel,

                      You can locate the thread in the Internet Programming Forum Here
                      Software makes Hardware Happen

                      Comment


                      • #12
                        Eric, have you done any performance testing on PB DLLs versus native php/mysql code (or .net/ASP on a windows server for that matter) for similar tasks?
                        Bernard Ertl
                        InterPlan Systems

                        Comment


                        • #13
                          Bern --

                          PHP is an interpreted language -- a script language which reads text-only "source code" files at runtime -- so I have been assuming that a well-written function in a fully-compiled Win32 DLL would be faster than PHP. There's no reason (AFAIK) that the code in the DLL shouldn't execute at full speed, and PowerBASIC DLLs are faster than just about anything else out there, so it didn't occur to me to be concerned about the speed.

                          I guess there could be some overhead involved in calling the DLL functions from PHP, but 1) the DLL is loaded into memory by PHP at startup, not on demand, and 2) during initialization, a pointer to the function entry point is passed to PHP, so I would also assume that calling it would be very fast. But I guess you never know. Unfortunately I am not fluent enough in PHP to create a fair test. I'm confident that I can write tight, efficient PB code, but any PHP code I wrote would not be "optimized", to say the least.

                          Any suggestions on how I could test it?

                          -- Eric
                          "Not my circus, not my monkeys."

                          Comment


                          • #14
                            Thanks everybody...

                            Based on the limited response in this thread, this won't become a full-fledged (help file, etc.) Development Tool from Perfect Sync. There just isn't enough demand.

                            But one of the participants in this thread has licensed the source code from us at (IMO) a modest fee. If anybody else is interested, now or in the future, please contact me by email.

                            -- Eric Pearson, Perfect Sync, Inc.
                            "Not my circus, not my monkeys."

                            Comment

                            Working...
                            X