manageProcess + redis 实现 ppt 转 pdf 服务
可以看到效果还是相当不错的,源文件是我从网上随便 down 的,具体链接可以参考我下面的附录; while (true) {
$this->flushTimestamp($pid);
$this->nowUuid = null;
$fileInfo = $redis->rpop(self::prefix);
if(!$fileInfo) {
sleep(1);
continue;
}
$output = '';
$uuid = $fileInfo['uuid'];
$this->nowUuid = $uuid;
$savePath = $fileInfo['savePath'];
$ext = $fileInfo['ext'];
$filename = $savePath . $uuid . ".$ext";
$res = [
'status' => 2,
'uuid' => $uuid,
'msg' => 'wait file sync'
];
$redis->set(self::prefix.'_'.$uuid,$res);
if(!file_exists($filename)) {
// 等待 NAS 服务同步数据
$this->flushTimestamp($pid);
sleep(3);
if(!file_exists($filename)) {
$res = [
'status' => -1,
'uuid' => $uuid,
'msg' => 'file not found,please try again!'
];
$redis->set(self::prefix.'_'.$uuid,$res);
$fileInfo['__REASON__'] = 'file not exist';
Fend_Log::write($fileInfo,$this->config['logName']);
continue;
}
}
if(md5_file($filename) != $fileInfo['filemd5']) {
$res = [
'status' => -2,
'uuid' => $uuid,
'msg' => 'file damage!'
];
$redis->set(self::prefix.'_'.$uuid,$res);
$fileInfo['__REASON__'] = 'file damage in nas!';
Fend_Log::write($fileInfo,$this->config['logName']);
continue;
}
$res = [
'status' => 2,
'uuid' => $uuid,
'msg' => 'process transforming...'
];
$redis->set(self::prefix.'_'.$uuid,$res);
exec("/usr/bin/libreoffice --invisible --convert-to pdf --outdir $savePath ".$filename,$output);
$res = [
'status' => 1,
'execOut' => $output,
'msg' => 'transform complete',
'path' => $savePath,
'name' => $uuid. ".$ext",
'uuid' => $uuid,
'ext' => $ext,
'fileName' => $filename
];
$redis->set(self::prefix.'_'.$uuid,$res);
}附录:
Last updated

