Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Feb 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PERL and PHP at the same time

    So I had my whole site written in PHP and at the last minute found out that the PHP functions to connect to Verisign don't work on my server. So I went ahead and got the PERL functions up and running, which is good. But now I am not sure how to integrate them. For instance, when a member joins, the join form posts to a php script which checks that all of their info was entered correctly, then *should* use the PHP function to charge their credit card, then, based on the response from Verisign, store their info and activate their account, or tell them they were declined. But now I'm using a PERL script to charge their account. I don't believe I can have a file with both PERL and PHP can I? If not, is there a way to maybe post to the first PHP file to check for problems, then automatically post to the PERL script, then post the response back to the last PHP script?
    Is there anyway to do this without completely rewriting the PHP script in to PERL?
    Thanks.

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,093
    Thanks
    11
    Thanked 101 Times in 99 Posts
    you can use virtual() to `include` your PERL script in your PHP page , though not sure if that will help or not without seeing exactly what is happening.

    Also what exactly is mising from your PHP version to stop it form doing whatever PERL is doing ?

    <off_topic>
    There is a PERL extension planned for PHP5 ! so you will then be able to mix your PERL & PHP .. until then ...
    </off_topic>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Feb 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks, I'll check that 'include' out. Sounds like exactly what I need though.
    I'm currently on a shared server and they say that when they try to compile PHP with Payflow Pro, it errors out for some unknown reason.

    Quote Originally Posted by firepages
    <off_topic>
    There is a PERL extension planned for PHP5 ! so you will then be able to mix your PERL & PHP .. until then ...
    </off_topic>
    Now that sounds cool.

  • #4
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You should not have any problems using PHP and Perl together. Just organize the flow so that it works. Both PHP and Perl use the same POST, GET methods on the server and both have excellent HTTP, FTP and even XML functions that allow you to send the same information between Perl and PHP scripts as you would PHP to PHP.

    As far as mixing the two it is not impossible but would require some other meddling. Like using passthru() in the PHP to execute the Perl and return its results.

    Code:
    passthru("perl script.pl?var=string&var2=string2");
    or virtual

    Code:
    virtual("perl script.pl?var=string&var2=string2");
    I have never tried this, though I am sure you can find help here using this solution.
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #5
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    I would think that the interoperability between PERL and PHP to be quite high. After all, PHP started as a bunch of little "PERL scripts".

  • #6
    New Coder
    Join Date
    Feb 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, it turns out virtual() doesn't work on my server either, but I have had some success with passthru(). I'm confused about how the results from passthru() get back into my PHP script though. For instance, consider the following 2 scripts:
    ----------
    1. Test1.php
    <?php
    $file="../cgi-bin/perlinclude.cgi";
    passthru ($file);
    ?>

    2. perlinclude.cgi
    #!/usr/bin/perl
    print "Hello World";
    ----------

    When I run Test1.php, I see Hello World. But I actually will not want to print the result but return it to some variable in the initial PHP script, and do some manipulation to it. How would I do this? Simply setting the passthru function equal to some variable didn't work, and in hindsight doesn't seem to make a lot of sense, but I'm not sure what else to do.

  • #7
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try using the return variable.

    Code:
    <?php
    $myVar = "";
    $file="../cgi-bin/perlinclude.cgi";
    passthru ($file,$myVar);
    
    print "the return variable content is: <b>" . $myVar ."</b>";
    ?>
    This is some interesting stuff. I'll have to visit activestate and get Perl installed on the machine so I can try this out

    at least it is more exciting than the datascrub i am doing on an Acces dB right now
    Last edited by carl_mcdade; 05-26-2004 at 07:32 PM.
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #8
    New Coder
    Join Date
    Feb 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I did, it just prints a 0 after Hello World (which I assume means the script executed successfully). I still don't see how you capture and send the data you want from the PERL script back to the PHP script though.

  • #9
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How about:

    Code:
    <?php
    $myVar = "";
    $file="../cgi-bin/perlinclude.cgi";
    
    /* I think passthru buffers automatically but why chance it?
    comment ob_start();  out as an experiment later*/
    
    ob_start(); 
    passthru ($file);
    $myVar = ob_get_contents();
    ob_end_clean();
    
    print "the return variable content is: <b>" . $myVar ."</b>";
    ?>
    Last edited by carl_mcdade; 05-26-2004 at 08:40 PM.
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #10
    New Coder
    Join Date
    Feb 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I get:

    ----------
    the return variable content is:
    ----------

    I don't know what the deal is; the manuel sure isn't very clear on passthru or virtual though.

  • #11
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Check the revised code above.
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #12
    New Coder
    Join Date
    Feb 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ----------
    the return variable content is: Hello World
    ----------

    Awesome. Thanks!

  • #13
    New Coder
    Join Date
    Feb 2004
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Last thing... (I think)
    I can't get the variables to pass to the cgi file. The test:

    ----------
    1. PayflowTest.php
    <?php
    $file="../cgi-bin/TransactionScript.cgi?var=1";
    passthru ($file);
    ?>

    2. TransactionScript.cgi
    #!/usr/bin/perl
    print $var;
    ----------

    It's not printing anything. I've tried as many different syntax tweaks as I can think of. Anyone see what's wrong?

  • #14
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It would seem that passtrhu is not the answer. Let's try exec() instead

    Code:
    <?php
    $myVar = "";
    $file="../cgi-bin/perlinclude.cgi?phpVar=string&phpVar1=string1";
    
    /* I think passthru buffers automatically but why chance it?
    comment ob_start();  out as an experiment later*/
    
    
    exec ($file,$myVar);
    
    print "the return variable content is:";
    foreach ($myVar as $key => $value) { 
       echo "<b>Key:</b> $key; Value: $value<br>\n"; 
    } 
     
    ?>
    I am having probelms getting perl to work on Apache 2 and Windows 2000 , otherwise I would run this code to check.

    I also found this in the docs:

    Code:
    Thanks to marat@provote.com who submitted a note about passing parameters from perl script back to php script with "exec". "exec" works just fine if you need to execute perl script from your php code once in a while. But if you want to optimize perl performance, you want to run it under mod_perl, right? You can use "fopen" in this case.
    The perl script runs under mod_perl and just prints out the variables it wants to pass to php script:
    #!/usr/local/bin/perl -w
    use strict;
    use CGI qw(-compile :all);
    my $q = CGI->new();
    print($q->header());
    print "It worked!!!\n";
    if(exists $ENV{MOD_PERL}) {
      print "we're running under mod_perl\n";
    }
    else {
      print "we're NOT running under mod_perl\n";
    }
    print "parameter1\n";
    print "parameter2";
    PHP script just calls this script with fopen and uses fgets to retrieve the output:
    $fp = fopen ("http://your.website.com/perl/perlscript.pl", "r");
    $i=0;
    while (!feof($fp)) {
           ${"par$i"} = fgets ($fp,4096);
           echo "parameter $i: ${"par$i"}";
           $i++;
    }
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials

  • #15
    Regular Coder
    Join Date
    May 2004
    Location
    sweden
    Posts
    236
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Okay her is the tested way to do this. I finally got perl going on this machine. You'll have to get to know some command line Perl because PHP calls perl.exe in that environment.

    In your perl script:

    Code:
    #!E:\xampp\xampp\perl\bin\perl.exe
    print "Content-type: text/html\n\n";
    print 'hello world from outside the cgi-bin';
    $ARGV[0] = $ARGV[0].' has been to perl land';
    print '<br>'.$ARGV[0]; // these are variables created from arguements 
    print '<br>'.$ARGV[1]; // fill them and play with them and get them 
    print '<br>'.$ARGV[2]; // ready to send back to the PHP script
    In your php:

    Code:
    <?php
    $myVar = "";
    $file="hey.cgi text1 text2 text3";
    
    ob_start(); 
    exec($file,$myVar);
    ob_end_clean ();
    
    print "the return variable content is: <b>";
    foreach ($myVar as $value) { 
       echo "<br>$value\n"; // remember those arguements above? They come back here! 
    } 
    
    print "</b>";
    ?>
    passthru() works nicely also because it returns just the last line rather than the whole file as an array.

    Code:
    <?php
    $myVar = "";
    $file="hey.cgi var1 var2 var3";
    
    ob_start(); 
    passthru("$file");
    $myVar = ob_get_contents();
    ob_end_clean ();
    
    print $myVar; 
    
    ?>
    the perl cgi

    Code:
    #!E:\xampp\xampp\perl\bin\perl.exe
    print "Content-type: text/html\n\n";
    print 'hello world from outside the cgi-bin';
    $ARGV[0] = $ARGV[0].' has been to perl land';
    print '<br>'.$ARGV[0];
    Last edited by carl_mcdade; 05-27-2004 at 10:46 PM.
    Carl McDade
    _____________
    Hiveminds Magazine
    for web publisher and community builders
    eRuby Tutorials


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •