Jquery和Swfupload导致整个网站大幅减速

时间:2015-06-04 12:07:12

标签: javascript php jquery web swfupload

我已经在网站上工作了一段时间,我最近遇到了一个我似乎无法弄清楚的问题。我是一个相对较新的Web开发人员,所以非常感谢帮助。

我正在使用swfupload处理音频上传到我的网站。我知道swfupload可以通过队列一次处理多个文件上传。然而,当我排队一长串的音频文件时,每个文件的上传速度都会变慢......用于处理上传的php代码如下所示。即使代码引用了很多其他帮助函数,我也会尽力解释我想要做的事情......

基本上除了用户授权检查等所有的漏洞外,代码还会创建一个存储在我的数据库中的临时“轨道”。曲目存储在某个专辑下(我将专辑称为发行版),一旦在该专辑下创建临时曲目,我就可以在该数据库条目下上传音频文件。我使用getID3来解析媒体文件,然后通过我从音频中提取的内容更新数据库中的轨道信息。

此代码工作正常,但如果我选择上传(排队)15个曲目上传,第15个曲目之后的曲目变慢,到第50个曲目...只需1个文件,上传将花费10多分钟。我知道可能会有很多问题造成这种情况,但我只是想知道是否有人暗示这个问题可能在哪里?

非常感谢!

 <?php

   private function saveBatchAudio($artist) {

    Utils::checkFileUpload();
    if ($this->isEditable($artist['artist_id'])) {
        require_once "Db/DbTracks.php";
        require_once "Db/DbReleases.php";

        $trackList = DbTracks::getTracksByReleaseHash($_POST['ReleaseHash'], 0, 100);
        $trackListOrder = count($trackList);

        $row = array(
            'track_name' => Utils::escape($_POST['Name']),
            'artist_id' => $artist['artist_id'],
            'release_hash' => Utils::escape($_POST['ReleaseHash']),
            'track_order' => $trackListOrder+1,
            'user_id' => $_SESSION['user']['user_id'],
            'track_upload_user_ip' => Utils::getIpAddress()
        );

                    $id = DbTracks::newTrack($row);
                    $this->log($artist, "User [{$_SESSION['user']['user_name']}] has created track:" . var_export($row, true));
    }
            else {
        echo json_encode(array(
            'message' => Utils::getMessage('e001')
        ));
    }


        require_once "Db/DbTracks.php";
        $track = DbTracks::getTrackById($id);

        if (!empty($track)) {
            $f = __FFM_ARCHIVE__ . $track['release_hash'] . '/' . $track['track_filename'];
            if (!empty($track['track_filename']) && file_exists($f)) {
                unlink($f);
            }


            include_once "formatting.php";
            $filename = wp_unique_filename(__FFM_ARCHIVE__ . $track['release_hash'], $_FILES['Filedata']['name']);

            $path = __FFM_ARCHIVE__ . $track['release_hash'] . '/' . $filename;
            if (!is_dir(dirname($path))) {
                wp_mkdir_p(dirname($path));
            }
            move_uploaded_file($_FILES["Filedata"]["tmp_name"], $path);

            require_once(dirname(__FILE__) . '/../../getid3/getid3.php');
            $getID3 = new getID3;
            $getID3->setOption(array('encoding' => 'UTF-8'));
            $info = $getID3->analyze($path);
            getid3_lib::CopyTagsToComments($info);
            $data = array(

                'track_name' => isset($info['tags']['id3v2']['title']['0']) ? $info['tags']['id3v2']['title']['0']  : $filename,
                'track_label' => isset($info['tags']['id3v2']['album']['0']) ? $info['tags']['id3v2']['album']['0']  : Utils::escape($_POST['Label']),
                'track_year' => isset($info['tags']['id3v2']['year']['0']) ? $info['tags']['id3v2']['year']['0']  : Utils::escape($_POST['Year']),
                'track_filename' => $filename,
                'track_size' => filesize($path),
                'track_length' => isset($info['playtime_seconds']) ? $info['playtime_seconds'] : 0,
                'track_bitrate' => isset($info['audio']['bitrate']) ? $info['audio']['bitrate'] : 0,
            );
            DbTracks::updateTrackById($track['track_id'], $data);

            $this->zipFolder(__FFM_ARCHIVE__ . $track['release_hash'], $track['release_hash']);

            $this->log($artist, "User [{$_SESSION['user']['user_name']}] has uploaded track");

            echo json_encode(array(
                'mp3' => $mp3 = __FFM_ARCHIVE_FRONT__ . $track['release_hash'] . '/' . $filename
            ));
        } else {
            echo json_encode(array(
                'message' => Utils::getMessage('e002')
            ));
        }

    }

&GT;

0 个答案:

没有答案