Community Forums
Connect with us on LinkedIn
Community Notice
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Feb 2010
    Posts
    7

    Default Use Perl and PHP in same script

    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. #2
    cPanel Staff cPanelJared's Avatar
    Join Date
    Feb 2010
    Location
    Houston, TX
    Posts
    1,032

    Default Friendly moderator note

    I moved this post from http://forums.cpanel.net/f42/how-aut...on-148065.html to its own topic.
    For hands-on assistance, please reference our new support information page: Where should I go for support?
    cPResources: Support Options - Submit a ticket here - Additional Support Options - Forums Search - Mailing Lists(Alt) - Documentation


    -- Jared Ryan, Technical Analyst, cPanel Technical Support

  3. #3
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Sep 2007
    Posts
    138

    Default

    crinte, can you please provide more information about what you are trying to accomplish?

  4. #4
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    496

    Default

    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 Code:
    #!/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
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

  5. #5
    Member This forum account has been confirmed by cPanel staff to represent a vendor. KostonConsulting's Avatar
    Join Date
    Jun 2010
    Location
    Austin, TX
    Posts
    42
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    You may want to check out the PHP module: PHP - search.cpan.org It allows you to execute PHP code from Perl.

    Alternatively, if you have simple PHP code, you can use PHP::Include: PHP::Include - search.cpan.org

  6. #6
    Integration Developer cPanelDavidN's Avatar
    Join Date
    Dec 2009
    Location
    Houston, TX
    Posts
    496

    Default

    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
    David Neimeyer
    Integration Developer

    sdk.cpanel.net
    APIs: XML-API API1 & API2
    Check Out: Developer Downloads Integration Blog
    Need Support? Support Ticket Developer Forum Feature Request

Similar Threads & Tags
Similar threads

  1. perl script in httpd
    By upsforum in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 05-28-2010, 10:03 AM
  2. how to identify account or PHP/Perl script used for spamming?
    By ShirazDindar in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 09-29-2007, 03:47 PM
  3. pipe email from exim to perl script, need help from exim & perl expert
    By markhard in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 04-21-2005, 11:56 AM
  4. PHP and PERL script access
    By dima in forum cPanel and WHM Discussions
    Replies: 3
    Last Post: 07-28-2003, 07:54 AM
  5. Executing a Perl script
    By oinkmedia in forum Themes and Branding
    Replies: 0
    Last Post: 07-20-2003, 06:07 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube