0

phpコードを使用して、cronを使用してコードを実行しています。cpanelでもcron時間とコマンドを設定しました。

1)。しかし、cronが実行されるたびにメールを受け取ります

/home/letsview/public_html/getfeed.php: line 1: ?php: No such file or directory
/home/letsview/public_html/getfeed.php: line 3: syntax error near unexpected token `'/home/letsview/public_html/wp-config.php''
/home/letsview/public_html/getfeed.php: line 3: `include_once('/home/letsview/public_html/wp-config.php');'

私はcpanelでこのコマンドを設定しました"/home/letsview/public_html/getfeed.php"

私もこのPHPを試しました:Cronジョブを介してスクリプトを実行しようとしてエラーが発生し、ファイルの先頭にこのコマンドを追加しました/usr/local/lib/php/が、まだ機能していません

これがcronファイルのコードですgetfeed.php

<?php
#!/usr/local/lib/php/
include_once('/home/letsview/public_html/wp-config.php');
include_once('/home/letsview/public_html/wp-includes/wp-db.php');
include_once('/home/letsview/public_html/wp-admin/includes/file.php');          
include_once('/home/letsview/public_html/wp-admin/includes/image.php');         
include_once('/home/letsview/public_html/wp-admin/includes/media.php');
global $wpdb;
 //property_type
$xml = simplexml_load_file("/home/letsview/public_html/letsviewproperties.xml",'SimpleXMLElement', LIBXML_NOCDATA);
$TotalPostadded = 0;
$TotalUseradded = 0;
foreach($xml as $child)
{
    //Insert Post
    $postdata = array();
    $postdata['post_title'] = trim($child->title);
    $postdata['post_content'] = trim($child->content);
    //$postdata['guid'] = trim($child->url);
    $postdata['post_status'] = 'publish';
    $postdata['post_type'] = 'post';
    $postdata['post_date'] = date('Y-m-d H:i:s');

    //Insert Post Meta
    $postmetadata = array();
    $addresstext = trim($child->FullAddress->address1);
    if($addresstext != ''){
        $addresstext .= ', ';
    }
    $addresstext .= trim($child->FullAddress->address2);
    if($addresstext != ''){
        $addresstext .= ', ';
    }
    $addresstext .= trim($child->FullAddress->address3);
    if($addresstext != ''){
        $addresstext .= ', ';
    }
    $addresstext .= trim($child->FullAddress->address4);
    $postmetadata['price'] = trim($child->price);
    $postmetadata['property_type'] = trim($child->type);
    $postmetadata['bed_rooms'] = trim($child->rooms);
    $postmetadata['bath_rooms'] = trim($child->bathrooms);
    $postmetadata['address'] = $addresstext;
    $postmetadata['add_city'] = trim($child->city);
    $postmetadata['add_state'] = trim($child->FullAddress->region);
    $postmetadata['add_country'] = trim($child->FullAddress->country);
    $postmetadata['add_zip_code'] = trim($child->postcode);
    $postmetadata['other_guid'] = trim($child->url);
    $postmetadata['post_from_feed'] = true;

    //Insert Author(agent)
    $authordata = array();
    $authormetadata = array();
    if(!empty($child->agent->agent_name)){
        //Author data
        $authordata['user_login'] = trim(pg_create_string($child->agent->agent_name));
        $authordata['user_nicename'] = trim($child->agent->agent_name);
        $authordata['display_name'] = trim($child->agent->agent_name);
        $authordata['user_email'] = trim($child->agent->agent_email);
        $authordata['user_url'] = trim($child->url);
        $authordata['role'] = trim('agent');
        $authordata['user_registered'] = date('Y-m-d H:i:s');
        //Author meta data
        $authormetadata['user_phone'] = trim($child->agent->agent_phone);
        $authormetadata['user_address'] = trim($child->agent->agent_address);
    }
    foreach($child->pictures as $pictures)
    {
        $postimagedata = array();
        $imageloop = 0;
        foreach($pictures as $picture)
        {
            $postimagedata[$imageloop] = (string)$picture->picture_url;
            $imageloop++;
        }
    }
    $postmetadata['post_from_feed_images'] = serialize($postimagedata);
    if($postdata['post_title'] != ''){
        $sql = "select count(post_title) as post from ".$wpdb->prefix."posts  where post_title = '".$postdata['post_title']."' and post_status = '".$postdata['post_status']."'";
        $sqlresult = $wpdb->get_results($sql);
        foreach ( $sqlresult as $post ) { 
            if($post->post == 0)
            {
                if(!empty($authordata)){
                    $user_id = wp_insert_user( $authordata );

                    if(!empty($user_id) && empty($user_id->errors)){
                        $TotalUseradded++;
                        echo "User added = ".$user_id."<br />";
                        if(!empty($authormetadata)){
                            foreach($authormetadata as $meta_key=>$meta_value){
                                add_user_meta( $user_id, $meta_key, $meta_value);
                                echo "User Meta = ".$meta_key." Inserted<br />";
                            }
                        }
                    }elseif(!empty($user_id->errors)){
                        $userdata = get_user_by('email', $authordata['user_email']);
                        $user_id = $userdata->ID;
                        echo "User fetched = ".$user_id."<br />";
                    }
                    $postdata['post_author'] = $user_id;
                }
                $post_id = wp_insert_post($postdata);
                if(!empty($post_id)){
                    $TotalPostadded++;  
                    echo "<br />"."Post Inserted = ".$post_id;
                    $properties_category_id = 109;
                    $cat = "INSERT INTO wp_term_relationships ( object_id, term_taxonomy_id ) VALUES ( '".$post_id."','".$properties_category_id."' )";
                    $catid = $wpdb->query($cat);
                    echo "<br />"."Post attached to Category ID = ".$properties_category_id."<br />";
                    if(!empty($postmetadata)){
                        foreach($postmetadata as $key=>$value){
                            add_post_meta($post_id, $key,$value, true);
                            echo "Post Meta = ".$key." Inserted<br />";
                        }
                    }
                }   
            }
        }
    }
}
$cron = "<br />"."Corn Done";
$cron .= "<br />"."Total Post added = ".$TotalPostadded;
$cron .= "<br />Total User added = ".$TotalUseradded;
echo $cron;
mail('xxxxxx@xxxxx.com','Lets view Properties Corn',$cron);
function pg_create_string($text)
{
  // replace all non letters or digits with -
  $text = preg_replace('/\W+/', '-', $text);

  // trim and lowercase
  $text = strtolower(trim($text, '-'));
  return $text;
} 
?>

誰でも私を助けることができますか??

4

3 に答える 3

2

ファイルの先頭は次のようになります。

#!/usr/bin/php
<?php

これは、PHPバイナリが/ usr/binフォルダーにあることを前提としています。そうでない場合は、#を変更してください。適切に線を引く。

さらに良い:

#!/usr/bin/env php
<?php

システムのenvコマンドを使用してphpがどこにあるかを判断するため、ほぼ確実に機能します。

于 2012-04-16T10:42:56.060 に答える
1

これをファイルの一番上に追加し、ファイルをchmodして権限(555または775)などを実行します。

#!/usr/local/lib/php
<?php
// your code

ここで、/ usr / local / lib/phpはphpへのパスです。

または、それが機能しない場合は、cronコマンドを変更できます。

/usr/local/lib/php /home/letsview/public_html/getfeed.php
于 2012-04-16T10:40:49.470 に答える
0
#!/usr/local/lib/php
<?php
// php code

そして、あなたは/ usr / local/libのphpcliを確認します

于 2012-04-16T10:42:04.377 に答える