我需要的方式产生的略图(用PHP5)一个图像管理脚本,并有一个问题,在那里我的主人有多种版本的PHP安装(4和5),与。PHP4定为默认。这意味着任何电话php从CLI会运行。PHP4.我已经想出了以下为什么我希望是一个交叉平台的解决方案。我将在这里主要是作为我有很多麻烦找到任何帮助,使用的是谷歌,所以这可能会帮助有人在未来,我还有以下问题。

  1. 你有看到任何明显的错误呢?
  2. 是否有任何其他路径php5二,你知道的,或知道有更好的了具有阵列为优化?
  3. 如果主机已经执行或shell_exec残疾人、会的EGalleryProcessQueue.php 脚本能够运行为的独立计划的工作吗?我没有访问时能够测试这个呢。我不是太担心这个问题,因为我会得到解决,以测试它最终无论如何。
  4. 没有任何人有任何建议的一种方式我可以得到一些反馈意见,因为多远,通过图像处理是什么?看到TODO部分EGalleryProcessQueue.php 我想显示的进展酒吧的时候是在管理部分。

主要剧本

/**
 * Writes the array to a text file in /path/to/gallery/needsThumbs.txt for batch processing.
 * Runs the thumbnail generator script in the background.
 *
 * @param array $_needsThumbs the array of images needing thumbnails
 */
private function generateThumbnails($_needsThumbs)
{
    file_put_contents($this->_realpath.DIRECTORY_SEPARATOR.'needsThumbs.txt',serialize($_needsThumbs));

    $Command = realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.'EGalleryProcessQueue.php '.$this->_realpath.' '.$this->thumbnailWidth.' '.$this->thumbnailHeight;

    if(PHP_SHLIB_SUFFIX == 'so')// *nix (aka NOT windows)
    {
        /*
         * We need to make sure we are using the right PHP version
         * (problems with shared hosts that have PHP4 and PHP5 installed,
         * but PHP4 set as default).
         */
        $phpPaths = array('php', '/usr/local/bin/php', '/usr/local/php5/bin/php', '/usr/bin/php', '/usr/bin/php5');
        foreach($phpPaths as $path)
        {
            exec("echo '<?php echo version_compare(PHP_VERSION, \"5.0.0\", \">=\"); ?>' | $path", $result);
            if($result)
            {
                shell_exec("nohup $path $Command 2> /dev/null > /dev/null &");
                break;
            }
        }
    }
    else // Windows
    {
        $WshShell = new COM("WScript.Shell");
        $WshShell->Run("php.exe $Command", 0, false);
    }
}

EGalleryProcessQueue.php

#!/usr/bin/php
<?php

if ($argc === 4 && strstr($argv[0], basename(__FILE__))) {
    // File is being called by the CLI and has not been included by another script

    if(!file_exists($argv[1].DIRECTORY_SEPARATOR.'needsThumbs.txt'))
    {
        // Either no thumbnails need to be created or a wrong directory has been supplied
        exit;
    }

    include(realpath(dirname(__FILE__)).DIRECTORY_SEPARATOR.'EGalleryThumbGenerator.php');

    $generator = new EGalleryThumbGenerator;
    $generator->directory = $argv[1];
    $generator->thumbnailWidth = is_int($argv[2]) ? $argv[2] : 128;
    $generator->thumbnailHeight = is_int($argv[3]) ? $argv[3] : 128;

    // $generator->processImages() returns the number of images left to process (it does them in blocks of 10)
    while (($i = $generator->processImages()) > 0)
    {
        /*
         * TODO Can we get some sort of feedback to the user here?
         * Possibly so that we can display a progress bar in the management section.
         * Probably have to write $i to a file to be read by the main script.
         */
    }

    exit;
}
?>
有帮助吗?

解决方案

你有看到任何明显的错误呢?

不,代码看起来很好。

是否有任何其他路径php5二,你知道的,或知道有更好的了具有阵列为优化?

这是一个很难回答的问题,因为PHP可能在任何地方安装一个服务器。这条路径你似乎是非常合乎逻辑要我,但那里能以任何数量的其他地方也可以安装。

而不是提供一堆目录,PHP5可能安装的,怎么样具有参数的用户已经设置提供路径PHP5可执行的,如果它不是在其美元的路径?

如果主机已经执行或shell_exec残疾人、会的EGalleryProcessQueue.php 脚本能够通过一个定时的工作?

我没有测试过它,但我们认为,将防止脚本运行。

没有任何人有任何建议的一种方式我可以得到一些反馈意见,因为多远,通过图像处理是什么?看到TODO部分EGalleryProcessQueue.php 我想显示的进展酒吧的时候是在管理部分。

储存的图像数量已完成的某处(文件、数据库,或许甚至会var)和有AJAX呼叫消防的每一秒或以这么一个功能,提供了完成vs总额。然后再用一些东西喜欢 http://docs.jquery.com/UI/Progressbar

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top