我的控制器的内核是这样代码删除表中的记录,但犯规加
protected function schedule(Schedule $schedule)
{
$schedule->call('\App\Http\Controllers\[email protected]')->everyMinute();
}
当我打电话控制器
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use Illuminate\Support\Facades\Storage;
use App\news;
use Auth;
use DOMDocument;
use Exception;
class HomeController extends Controller
{
public function automatic()
{
function delete(){
DB::table('news')->delete();
echo "table deletted";
}
delete();
}
}
它删除表中的记录。但是当我打电话给这个代码的控制器
class HomeController extends Controller
{
public function automatic()
{
function follow_links_reportersnepal($url,$cat)
{
ini_set('max_execution_time', 9000);
global $already_crawled;
global $crawling;
$i=0;
$doc = new DOMDocument();
@$doc->loadHTML(@file_get_contents($url));
$linklist = $doc->getElementsByTagName("a");
$already_crawled[]="sailaab";
foreach ($linklist as $link)
{
try {
$l = $link->getAttribute("href");
if(strlen($l)==45)
{
if (!in_array($l, $already_crawled))
{
$i++;
if ($i>2) {
break;
}
$already_crawled[] = $l;
$content = file_get_contents($l);
$first_step = explode('<h3 class="display-4">' , $content);
$second_step = explode('</h3>' , $first_step[1]);//title
$third_step=explode('<div class="entry-content">',$second_step[1]);
$fourth_step=explode('<p>',$third_step[1]);
$fifth_step=explode('<div class="at-below-post', $fourth_step[1]);
$sixth_step=explode('<figure class="figure">', $content);
if(isset($sixth_step[1])){
$seventh_step=explode('src="', $sixth_step[1]);
$eighth_step=explode('"', $seventh_step[1]);
$url = $eighth_step[0];
$img=rand();
$img=(string)$img;
file_put_contents($img, file_get_contents($url));
$user = Auth::user();
news::create([
'news_title'=>strip_tags($second_step[0]),
'category_id'=>$cat,
'source_id'=>'reportersnepal',
'reference_url'=>"www.reportersnepal.com",
'reference_detail'=>$l,
'news_summary'=>"null",
'news_detail'=>strip_tags($fifth_step[0]),
'news_image'=>$img,
'news_video'=>"null",
'news_status'=>"1",
'created_by'=>$user->id,
'last_updated_by'=>$user->id,
]);
}
else{
$user = Auth::user();
news::create([
'news_title'=>strip_tags($second_step[0]),
'category_id'=>$cat,
'source_id'=>'reportersnepal',
'reference_url'=>"www.reportersnepal.com",
'reference_detail'=>$l,
'news_summary'=>"null",
'news_detail'=>strip_tags($fifth_step[0]),
'news_image'=>"default.png",
'news_video'=>"null",
'news_status'=>"1",
'created_by'=>$user->id,
'last_updated_by'=>$user->id,
]);
}
}
}
} catch (Exception $e) {
continue;
}
}
}
follow_links_reportersnepal('http://reportersnepal.com/category/featured','1');
}
}
它没有写任何东西在我的数据库表中。当我回显变量时,它显示数据。 当我手动调用它们时,此代码正常工作。
而我的cron选项卡
php-cli -q /home/allnewsnepal/public_html/artisan schedule:run
是从命令行调用的吗? – sumit
以及你如何安排它?你可以发帖 – Exprator
是的,我已经给出了细节。 在命令行中我称之为 php artisan日程安排:运行 –