Forums

Running a console script (7 posts)

  1. Detective
    Member
    Posted 1 month ago #

    Using regular WordPress, I can create console PHP scripts just including wp-config.php and accessing WordPress' functions. Those scripts are mainly cronjobs that perform maintenance.

    However, in MU I can't do this. The scripts ends execution.

    The last script I wanted to run was a converter from a stand-alone installation of bbPress to a new BuddyPress installation.

    <?php
    define( 'WP_USE_THEMES', false );
    $blog_id = 1;
    require( dirname( __FILE__ ) . '/html/wp-config.php' );
    do_action( 'bbpress_init' );
    remove_all_actions( 'bbpress_init' );
    /*
    code that fetchs the forum data and correctly inserts
    them in the new installation
    */
    ?>

    If I run the script accessing via HTTP everything works OK. If I run it on the console by typing:

    php bbpress_importer.php

    Execution ends inmediately.

    This does not happen with regular WordPress. Any clue? Does anybody have had a similar problem?

    Thanks.

  2. tdjcbe
    Member
    Posted 1 month ago #

    Have to admit I've not seen that practice before. I've always seen /wp-blog-header.php be the file called. Take a look at the root directory's index.php file for usage.

  3. andrea_r
    Member
    Posted 1 month ago #

    "The last script I wanted to run was a converter from a stand-alone installation of bbPress to a new BuddyPress installation. "

    There's a new option in the latest buddypress to hook up a pre-existing bbPress install. It's under the BuddyPress menu, under Forums setup. Not sure how well it works.

  4. Detective
    Member
    Posted 1 month ago #

    Andrea, the BuddyPress usage is not what I need. And also I need more console scripts to work, not just this one :)

    tdjcbe, it's not a common practice ;). For example, I run a cronjob to extract statistics every day. Loading wp-blog-header and looking at index.php only gives you the conclusion that the best file to load in a script is wp-config.php.

    The WP cron system is not suitable for stuff that needs to be done exactly at the same time every day, because it relies on http requests and it's still a process under the webserver. Sometimes you need to run a script under your user and not apache, without security restrictions or limited permissions.

    There are many scenarios where this stuff is useful. And in single WP it works right out the box. I tried to track the problem, without luck :(

  5. SteveAtty
    Member
    Posted 1 month ago #

    There was a change in one of the core WPMU files which means that command line executed php no longer works. The only way to do it is basically clone two or three of the core files and edit one single line in one of them and then change your file so it doesn't use wp-config.php but a different file.

    I documented it here:

    http://mu.wordpress.org/forums/topic/14750?replies=4

  6. Detective
    Member
    Posted 1 month ago #

    Thanks, Steve!! I tried to search the forum, but it seems I didn't use the right keywords.

    Thanks again :)

  7. error
    Member
    Posted 1 week ago #

    If you set $_SERVER['HTTP_HOST'] yourself before loading up wp-blog-header.php then everything works fine. Set it to the vhost of the blog you want your script to operate on. (If you're using subdirectories you're on your own.)

Reply

You must log in to post.

About this Topic