Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Use Perl and PHP in same script

Discussion in 'cPanel Developers' started by crinte, Sep 8, 2010.

  1. crinte

    crinte Member

    Joined:
    Feb 17, 2010
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    51
    Does anyone know, if I can use perl and php together in postwwwacct or no? If not, does anyone know, how to pass some variables on to php script in postwwwacct perl script and execute it with exec?

    Thanks!
     
  2. cPanelJared

    cPanelJared Technical Analyst

    Joined:
    Feb 25, 2010
    Messages:
    1,835
    Likes Received:
    20
    Trophy Points:
    143
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. sirdopes

    sirdopes Well-Known Member
    PartnerNOC

    Joined:
    Sep 25, 2007
    Messages:
    141
    Likes Received:
    0
    Trophy Points:
    66
    crinte, can you please provide more information about what you are trying to accomplish?
     
  4. cPanelDavidN

    cPanelDavidN Integration Developer

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    3
    Trophy Points:
    68
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Hi crinte,

    If I understand you correctly, you have a Perl postwwwacct script and you have PHP code that you want executed too? There is no good way to mesh the two into one script. It's be best to have the Perl fire a system() or exec() function (or something else) that calls the PHP code. Provided that the PHP doesn't have to be executed by Apache (or other webserver), here's a way to do it:

    You could do something like this in your Perl postwwwacct script

    Code:
    @args = ("/my/php/cli/script.php", "key1", "value1", "key2", "value2");
        system(@args) == 0
            or die "system @args failed: $?"
    

    then you can use PHP code like this to store the key/value pairs into a PHP associative array

    PHP:
    #!/bin/usr/php
    //$argv is a special variable, http://php.net/manual/en/reserved.variables.argv.php
    <?php
    function argv2array ($argv) {
            
    $opts = array();
            
    $argv0 array_shift($argv);
     
            while(
    count($argv)) {
                    
    $key array_shift($argv);
                    
    $value array_shift($argv);
                    
    $opts[$key] = $value;
            }
            return 
    $opts;
      }

    // test function!
    $nice_array argv2array($argv);
    var_dump($nice_array);

    Regards,
    -DavidN
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  5. KostonConsulting

    KostonConsulting Well-Known Member

    Joined:
    Jun 17, 2010
    Messages:
    255
    Likes Received:
    1
    Trophy Points:
    68
    Location:
    San Francisco, CA
    cPanel Access Level:
    Root Administrator
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  6. cPanelDavidN

    cPanelDavidN Integration Developer

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    3
    Trophy Points:
    68
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Fortunity is correct, there are a few bridges out there. I did not mention them explicitly because I feel for this particular situation the benefit of using such a bridge is out weighted by the stability, safety, and ease of use when implementing a solution similar to the one I provided.

    Crinte, the Perl code you're referring to would happen to be the postwwwacct script hook that Matt provided here. If so, you'll notice in that thread, I've updated it by posting a link to a blog post where, in detail, I explain how to write a PHP script hook that does MySQL database and user creation and privilege assignment all using the APIs.

    Regards,
    -DavidN
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice