Inkscape 服务器命令行转换非常慢:一个文件需要 12 秒
Inkscape server command line very slow conversion : 12 seconds for one file
我需要将 ai 和 eps 文件转换为 svg 以便与产品定制工具一起使用。
为此,我将 ai 或 eps 转换为 eps(以删除文件周围的任何画板或空白区域),然后转换为 svg。
所有这些都是在使用此 PHP 代码上传原始文件后完成的:
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 之外,还有其他方法可以进行此转换吗?
编辑:所以我尝试 运行ning 一个 shell 脚本,它需要相同的时间,但是,如果我 运行 脚本直接在服务器上它会占用更短的时间。所以看起来问题是一些等待,因为即使最终创建了文件,也缺少权限。这是我从 php 运行ning 时得到的输出:
** (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:因此,在授予文件夹权限后,我不再有脚本的输出,创建了文件,但与直接在服务器上 运行ning 相比,它仍然需要大量时间。
原来问题是安装的字体数量。似乎 inkscape 在开始时加载了所有字体,因为我安装了整个 google 字体,所以它花了很长时间。
所以我删除了所有 google 字体,然后 运行 fc-cache
进行更新。
我也从 0.48 更新到 0.91,这似乎也得到了很好的性能提升。当我仍然安装字体时,脚本在第一个 运行 上花了 80 秒,但在第二个 运行 上只用了 13 秒,而在 0.48 的情况下我一直在 22/24 秒左右。
现在脚本 运行 不到一秒,谢天谢地!
现在的另一个改进是 运行 使用 Inkscape 的 shell 模式的两个命令,以避免它被加载两次。
权限问题也是由 SELinux 引起的,由 apache 用户主目录 .config
文件夹中的 chcon
解决
我需要将 ai 和 eps 文件转换为 svg 以便与产品定制工具一起使用。 为此,我将 ai 或 eps 转换为 eps(以删除文件周围的任何画板或空白区域),然后转换为 svg。 所有这些都是在使用此 PHP 代码上传原始文件后完成的:
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 之外,还有其他方法可以进行此转换吗?
编辑:所以我尝试 运行ning 一个 shell 脚本,它需要相同的时间,但是,如果我 运行 脚本直接在服务器上它会占用更短的时间。所以看起来问题是一些等待,因为即使最终创建了文件,也缺少权限。这是我从 php 运行ning 时得到的输出:
** (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:因此,在授予文件夹权限后,我不再有脚本的输出,创建了文件,但与直接在服务器上 运行ning 相比,它仍然需要大量时间。
原来问题是安装的字体数量。似乎 inkscape 在开始时加载了所有字体,因为我安装了整个 google 字体,所以它花了很长时间。
所以我删除了所有 google 字体,然后 运行 fc-cache
进行更新。
我也从 0.48 更新到 0.91,这似乎也得到了很好的性能提升。当我仍然安装字体时,脚本在第一个 运行 上花了 80 秒,但在第二个 运行 上只用了 13 秒,而在 0.48 的情况下我一直在 22/24 秒左右。
现在脚本 运行 不到一秒,谢天谢地!
现在的另一个改进是 运行 使用 Inkscape 的 shell 模式的两个命令,以避免它被加载两次。
权限问题也是由 SELinux 引起的,由 apache 用户主目录 .config
文件夹中的 chcon
解决