PHP Script is Timing out.

I am trying to run a script on my hosting account to find photos that were stored in various directory so I can get the correct file path and then move them into a new directory based upon the gallery name.

I have it running but some of the galleries have almost 200 photos and the script stops working part way through. Not sure how to fix it.

[php]

<?php $servername = ""; $username = ""; $password = ""; $dbname = ""; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } set_time_limit(0); ignore_user_abort(1); ////////////////////////////////////////////////////////////////////////// //////////// SEARCH FUNCTION /////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////// function rsearch($folder, $pattern) { $iti = new RecursiveDirectoryIterator($folder); foreach(new RecursiveIteratorIterator($iti) as $file){ if(strpos($file , $pattern) !== false){ return $file; } } return false; } ////////////////////////////////////////////////////////////////////////// $sql = "SELECT id, name FROM prc_igallery order by id ASC"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["name"]. "
"; $gallery_id = $row["id"]; //$gallery_id = "7"; $gallery_name = $row["name"]; //The name of the directory that we need to create. $directoryName = $gallery_name; //Check if the directory already exists. if(!is_dir($directoryName)){ //Directory does not exist, so lets create it. mkdir($directoryName, 0755); } /////////////////////////////////////////////////////////////////////////////////////////////////// // NOW FIND INDIVIDUAL PHOTOS FOR EACH GALLERY///////////////////////////////////////////////////// $sql2 = "SELECT * FROM prc_igallery_img where gallery_id = $gallery_id order by id ASC"; $result2 = $conn->query($sql2); $rowcount=mysqli_num_rows($result2); printf("Result set has %d rows.\n",$rowcount); echo("

"); if ($result2->num_rows > 0) { // output data of each row while($row2 = $result2->fetch_assoc()) { echo "gallery id: " . $row2["gallery_id"]. " - Photo: " . $row2["filename"]. "
"; //////////////////////////////////////////////////////////////////////////////////////////////////// //// FIND FILE IN IGALLERY DIRECTORY ////////////////////////////////////////////////////////////// $folder = "/home/content/r/c/p/quake/html/images/igallery/original/"; $pattern = $row2["filename"]; /////////////////////////////// /// call search function //// ////////////////////////////// $filepath = rsearch($folder, "/".$pattern); ///////////////////////////////////////////// echo $filepath; echo ("

"); unset($folder); unset($pattern); unset($filepath); //sleep(2); //////////////////////////////////////////////////////////////////////////////////////////////////// } } else { echo "0 results"; } $gallery_id=""; // Free result set mysqli_free_result($result2); echo "

"; /////////////////////////////////////////////////////////////////////////////////////////////////// } } else { echo "0 results"; } $conn->close(); ?>

[/php]

I do not get an error code… the page just stops responding.

Based on the code, you will run out of memory rather quickly. This is kind of an odd way to go about what you are trying to do.

How many directories are there to search thru?

I know its really bad… I am not a programmer and the very little I know has lead to my issue.

There are 92 directories that must be searched.

What is the value of the database currently?

If you store the path in the database, where the files are is immaterial. Now, if you are using the directory as a way to show images for a specific gallery, the database isn’t getting use.

The DB does not have the path to the images. thus the need to search.

The needed end result is a list of 186 gallery directories with the correct photos in each directory.

Once the photos are in the correctly labeled gallery directory this information / images will be ported into a new website gallery.

Is part of the fixing process adding them to the database, of just moving the files to the new location?

Longstory —

The gallery was apart of an old Joomla 1.5 site that was hacked. A new site has been created in Joomla 3 but with an entirely different Joomla Gallery component.

The goal is to save the photos from the old site and load them into the new gallery component.

However, in order to do this - the photos much be placed into their own unique gallery directories with the correct photos per the sql tables of the old Joomla 1.5 igallery component.

see the images for what these look like and why I find it hard to easily pluck out the photos needed.


I know the sql table says a folder name but that’s not how they were stored on the backend on the Joomla 1.5 site. but rather in the format of the first screen print.

okay, I get the problem set now.

Do you have ssh access on the new server? The best place for this to run is as a script, not as a page if you understand what I’m saying.

Is that something you would do through PUTTY?

If so, I think I can do that …

Yes, Putty gives you ssh access on a Windows OS.

Yes, I can SSH to the host with the source files. But that is all about I know how to do.

Sponsor our Newsletter | Privacy Policy | Terms of Service