WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: W3 Total Cache] Standalone php script, traped in the enhanced disk cache (6 posts)

  1. avatarworf
    Member
    Posted 4 years ago #

    I've got a simple php script which interacts with my WP install to update a few database records.

    I noticed after I updated the Page Caching from disk (basic) to disk (enhanced) my php script, which I run as a cron entry started to return me my homepage; after the second or third run.

    In my PHP script I have include_once('wp-config.php'); which sets up the needed environment.

    Any Ideas on how I can allow my script to run naturally. I have placed the script name into the exclude list, with no success.

  2. Frederick Townes
    Member
    Posted 4 years ago #

    Can you paste the script file contents here?

  3. avatarworf
    Member
    Posted 4 years ago #

    Here you are; basically it reads IDs from a table; searches an XML document, and updates the records in the table. I've removed most of the error checking to make it more readable for you.

    <?php
    include_once('wordpress/wp-config.php');
    #include_once('wordpress/wp-load.php');
    #include_once('wordpress/wp-includes/wp-db.php');

    $results = $wpdb->get_results("select id,slug from travel_wp_affproducts WHERE id > 50");

    $ProductList = array ();
    $Slugs = array ();

    foreach ($results as $id) {
    array_push($ProductList, $id->id);
    $Slugs[ $id->id ] = $id->slug;
    }

    $xml = simplexml_load_file('wordpress/i/data.wiggle');

    foreach ($ProductList as $prodID) {
    $result = $xml->xpath("//prod[@id='$prodID']");

    if ( ! empty($result) ) {

    $name = $xml->xpath("//prod[@id='$prodID']/text/name");
    $url = $xml->xpath("//prod[@id='$prodID']/uri/awTrack");
    $price = $xml->xpath("//prod[@id='$prodID']/price/buynow");

    $db_insert = "INSERT INTO travel_wp_affproducts SET id='$prodID',\n";
    $db_insert .= 'name="'. $name[0] .'", ';
    $db_insert .= "url='$url[0]', ";
    $db_insert .= "stamp=now(), ";
    $db_insert .= "value='£".preg_replace('/\.00$/','',$price[0])."' \n";
    $db_insert .= "ON DUPLICATE KEY UPDATE \n";
    $db_insert .= 'name="'. $name[0] .'", ';
    $db_insert .= "url='$url[0]', ";
    $db_insert .= "stamp=now(), ";
    $db_insert .= "value='£".preg_replace('/\.00$/','',$price[0])."'; \n";

    $success = $wpdb->query($db_insert);
    }

  4. Frederick Townes
    Member
    Posted 4 years ago #

    For now add define('DOING_CRON', true); to your script, later define('DONOTCACHEPAGE', true); will be available for use in similar scripts in the upcoming release.

  5. avatarworf
    Member
    Posted 4 years ago #

    Thanks Very much..

  6. Frederick Townes
    Member
    Posted 4 years ago #

    You're welcome.

Topic Closed

This topic has been closed to new replies.

About this Topic