我需要将ai和eps文件转换为svg以与产品定制工具一起使用。 为此,我将ai或eps转换为eps(以删除文件周围的任何画板或空白区域),然后转换为svg。所有这一切 是原始文件与此PHP代码上传后进行:Inkscape服务器命令行转换非常慢:一个文件需要12秒
if(!empty($_FILES))
{
//$rustart = getrusage();
//var_dump($_FILES);
$tempFile = $_FILES['file']['tmp_name'];
$filePrefix = "file_" . time() . "_";
$targetName = $this->santitizeFilename($_FILES['file']['name']);
//var_dump($targetName);
$finalName = $filePrefix . $targetName;
$targetFile = $rootFolder . $ds . $finalName;
move_uploaded_file($tempFile, $targetFile);
$response['filepath'] = $relativeFolder . $ds . $this->getFilenameWithExtension($targetFile);
//$response['success'] = file_exists($targetFile);
$response['id_file'] = -1;
$ext = pathinfo($targetFile, PATHINFO_EXTENSION);
if($ext == 'svg')
{
$response['filepath'] = $relativeFolder . $ds . $this->replaceExtension($targetFile, 'svg');
}
if($ext == 'ai' || $ext == 'eps')
{
$epsPath = $rootFolder . $ds . $this->replaceExtension($targetFile, 'eps');
$epsCmd = "inkscape " . $targetFile . " -D -E " . $epsPath;
$startEps = microtime(true);
exec($epsCmd);
$endEps = microtime(true);
$svgPath = $rootFolder . $ds . $this->replaceExtension($targetFile, 'svg');
$svgCmd = "inkscape " . $epsPath . " --export-plain-svg=" . $svgPath;
$startSvg = microtime(true);
exec($svgCmd);
$endSvg = microtime(true);
$response['epsTime'] = $endEps - $startEps;
$response['svgTime'] = $endSvg - $startSvg;
$response['filepath'] = $relativeFolder . $ds . $this->replaceExtension($targetFile, 'svg');
$vectorFile = new MCVectorFile();
$vectorFile->url = $epsPath;
if($vectorFile->save()){
$response['id_file'] = $vectorFile->id;
}
}
当登录时间$ epsTime和$ svgTime我得到约12秒每次。 这真的很长,我没有看到它与多个用户同时上传文件的网站上的多个用户...
也运行只有一个命令不会改善时间,它仍然需要大约12秒每个命令。
有什么办法可以加快速度吗?除了inkscape之外,还有其他方法可以进行这种转换吗?
编辑:所以我已经尝试运行一个shell脚本,而它需要相同的时间,但是,如果我直接在服务器上运行脚本,它需要花费更少的时间。因此,即使文件最终被创建,似乎问题仍然存在,因为缺少权限。这是我从php运行时得到的输出:
** (inkscape:31337): WARNING **: Unable to create profile directory (Permission denied) (13)
** Message: Cannot create profile directory /usr/share/httpd/.config/inkscape.
** Message: Inkscape will run with default settings, and new settings will not be saved.
** (inkscape:31337): WARNING **: Could not create extension error log file '/usr/share/httpd/.config/inkscape/extension-errors.log'
** (inkscape:31344): WARNING **: Unable to create profile directory (Permission denied) (13)
** Message: Cannot create profile directory /usr/share/httpd/.config/inkscape.
** Message: Inkscape will run with default settings, and new settings will not be saved.
** (inkscape:31344): WARNING **: Could not create extension error log file '/usr/share/httpd/.config/inkscape/extension-errors.log'
我不确定我应该给这些文件夹的权限给apache。但看起来这些是我可能不需要的Inkscape的配置。那么有什么办法可以绕过这个吗?
编辑2:所以在给予文件夹的权限后,我再也没有脚本输出,文件被创建,但与直接在服务器上运行相比,它仍然需要大量的时间。