Jquery and Swfupload causing whole website to slow down drastically

89 Views Asked by At

I have been working on a website for a while and I recently encountered a problem that I can't seem to figure out. I am a relatively new web developer so help would be greatly appreciated.

I am using swfupload to handle audio uploads to my website. I am aware that swfupload has the power to handle multiple file uploads at once through a queue. However, when I queue up a long list of audio files, the uploading would begin to get slow and slower with each file...The php code used to handle the uploading is given below. Even though the code references a lot of other helper functions, I will do my best to explain what I am trying to do...

Essentially with all the fluff aside such as user authorization checks..etc, the code creates a temporary "track" which is stored in my database. Tracks are stored under a certain album(I refer to albums as releases) and once a temporary track is created under that certain album, I can then upload an audio file under that database entry. I use getID3 to parse the media file and then update the track information in the database by whatever I can pull from the audio.

This code works fine but if I select over (queue up) 15ish tracks to upload, the tracks after the 15th one becomes slow and by the 50th track...uploading will take over 10 minutes for just 1 file. I know there can be a lot of issues causing this but I was just wondering if anyone had a hint on where this issue might be?

Thanks a lot!

 <?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')
            ));
        }

    }

?>

0

There are 0 best solutions below