doumi0737 2014-05-08 05:49
浏览 56
已采纳

Cronjob没有按预期工作(php文件)

I have written a script for my customer which downloads youtube videos and uploads them to dailymotion. When I run dailyuploader.php with browser it works Ok.

Also when I run it from terminal;

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
dosya:/www/gokhan/uploads/27-nefes-fuibron-yar-dedim-sana-dj-karaduman-2013.mp4
Directory:/www/gokhan/uploads/27-nefes-fuibron-yar-dedim-sana-dj-karaduman-2013.mp4
Array
(
    [id] => x1tjwo8
    [title] => 27 Nefes & Fuibron - Yar Dedim Sana (Dj Karaduman 2013)
    [channel] => music
    [owner] => x1e8kjt
)
Basarili

It works Ok.

But when i add it to crontab It doesn't work as expected.

I get output;

X-Powered-By: PHP/5.4.28
Content-type: text/html

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
dosya:
Directory:
Dosya yok ya da 0kb

My cron command is like this: */20 * * * * /usr/bin/php-cgi /www/gokhan/dailyuploader.php >> /www/gokhan/out.txt

Also I use commands that needs high permissions: rename, (exec with youtube-dl: an application that downloads youtube videos) etc.

Also I have even tried to make chmod 777 all files and directories. Also I have changed owner of files to root but result was same.

Any help appreciated.

Edit.1 function that downloads video.

function download_video($videoid){
    exec('youtube-dl '. $videoid .' -o "/www/gokhan/uploads/%(title)s.mp4"');
    return true;
}

function that gets video path and title to upload.

function get_file(){
$dir = opendir("/www/gokhan/uploads/");
while (($dosya = readdir($dir)) !== false)
{
    if(! is_dir($dosya)){
        $title = substr($dosya,0,-4);
        $direc = "/www/gokhan/uploads/";
        $t = seola(substr($dosya,0,-3)).".mp4";
        rename($direc.$dosya, $direc.$t);
        $tabi = $direc.$t;
    }
}
closedir($dir);
echo "dosya:".$tabi."
";
$ar['dosya'] = $tabi;
$ar['title'] = $title;
return $ar;
}

function that uploads file to dailymotion

function upload_to_dailymotion($username,$password,$dir,$title){
include('/www/gokhan/Dailymotion.php');
require_once '/www/gokhan/Dailymotion.php';
echo "Directory:".$dir."
";
$apiKey = "apikey";
$apiSecret = "apisecret";
$api = new Dailymotion();
$api->setGrantType(Dailymotion::GRANT_TYPE_PASSWORD, $apiKey, $apiSecret, array('write','delete'),
array('username' => $username, 'password' => $password));
if(file_exists($dir) and filesize($dir) > 0){
    $url = $api->uploadFile($dir);
    $result1 = $api->post('/me/videos', array('url' => $url, 'title' => $title , 'description' => '' , 'channel' => 'music', 'tags' => '', 'published' => true));
    print_r($result1);
    $url = $result1['id'];
    return $url;
}
else
    die("Dosya yok ya da 0kb");
}

Edit.2 Function that connects all methods obove..

function download_get_link($videoid,$username,$password){
$indirme = download_video($videoid);
$ar= get_file();
$title = $ar['title'];
$dir = $ar['dosya'];
if($indirme){
    $url = upload_to_dailymotion($username,$password,$dir,$title);
    $res['url'] = $url;
    $res['title'] = $title;
    $res['description'] = '';
    return $res;
}
  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 session失效问题
      • ¥15 GMS地下水数值模拟无法打开
      • ¥15 树型结构的数据怎么匹配分支
      • ¥15 stm32F4用.引不出来结构体成员怎么解决
      • ¥15 .exe文件打不开怎么解决?
      • ¥30 Syntax Error: TypeError: this.getOptions is not a function的问题
      • ¥15 eclipse Android环境搭建
      • ¥15 unity中脚本之间的继承有什么作用
      • ¥15 C语言内存对齐代码不太理解
      • ¥15 uniapp中的uni-file-picker组件多图上传,删除,显示。以及C#.Net后端处理问题