我使用 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: Error trying to run a script via Cron job并在文件顶部添加了这个命令,/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;
}
?>
谁能帮我??