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 之外,还有其他方法可以进行此转换吗?

编辑:所以我尝试运行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:因此,在授予文件夹权限后,我不再从脚本中输出,可以创建文件,但与直接在服务器上运行相比,它仍然需要花费大量时间。

所以事实证明问题在于安装的字体数量。似乎inkscape在开始时加载了所有字体,并且由于我安装了整个Google字体,因此花了很长时间。

所以我通过删除它们来删除所有谷歌字体,并运行fc-cache进行更新。

我还从 0.48 更新到 0.91,这似乎也得到了很好的性能提升。当我仍然安装字体时,脚本在第一次运行时需要 80 秒,但在第二次运行时只有 13 秒,而 0.48 我始终在 22/24 秒左右。

现在脚本运行不到一秒钟,谢天谢地!

现在的另一个改进是使用 Inkscape 的 shell 模式运行这两个命令,以避免它被加载两次。

此外,权限问题是由 SELinux 引起的,并通过 apache 用户主页目录中.config文件夹上的chcon解决