/    Sign up×
Community /Pin to ProfileBookmark

PHP Timeout Issue

I’m having a problem with my PHP script timing out. From what I’ve determined, the problem lies in the section of my script where some image resizing takes place. If I echo text to the screen/browser after EACH image is resized, there is no problem and the script executes/finishes as desired. BUT, when I don’t have any text sent to the screen/browser, the script will appear to timeout (no error message is given) after a few seconds.

Basically, here is how the script is setup:

A “for” loop is run for the length of the number of files that were uploaded (10 max).
For each uploaded file, it is resized twice. After this, the file details are sent to a database.
These actions are repeated for each uploaded file.

Again, if I output text to the screen after EACH file is resized and recorded in database, there is no problem. But if I do not output text to the screen (this is what I desire), the script appears to do one of two things:
1. Resize/record each file as specified BUT not do the remaining action(s) of the script – namely redirect the user to another page (header).
2. Resubmit itself and repeat the actions above, so in essense, if I have 6 uploaded files, it will resize/record this batch TWICE.

Any help would be appreciated.

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@tegraphixOct 24.2005 — if you post the actual code, it would help people determine the problem
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYOct 24.2005 — it might at least give us an idea of what we're up against ?
Copy linkTweet thisAlerts:
@badg0003authorOct 24.2005 — Here is the code-listing for the script in question. I include a lot of external files which I've not included in the code listing - let me know if you want them listed as well.

<i>
</i>&lt;?php
set_time_limit(86400);

<i> </i>/**************************************************************************
<i> </i> MODULES
<i> </i>**************************************************************************/
<i> </i>include_once("modules/function.Config.php");
<i> </i>include_once(PATH_MODS . "class.Template.php");
<i> </i>include_once(PATH_MODS . "class.MySQL.php");
<i> </i>include_once(PATH_MODS . "class.Authentication.php");
<i> </i>include_once(PATH_MODS . "class.Upload.php");
<i> </i>include_once(PATH_MODS . "class.Validate.php");
<i> </i>include_once(PATH_MODS . "class.Session.php");
<i> </i>include_once(PATH_MODS . "function.ErrorReport.php");


<i> </i>/**************************************************************************
<i> </i> SESSION MODULE
<i> </i>**************************************************************************/
<i> </i>$objSession = new Session();
<i> </i>if(!$objSession-&gt;Status("GALLERY_DATA")) {
<i> </i> header("Location:" . PATH_ROOT . "gallery_chooser.php");
<i> </i> exit();
<i> </i>}


<i> </i>/**************************************************************************
<i> </i> CONSTANTS
<i> </i>**************************************************************************/
<i> </i>define("SUBMIT_ADDNOW", "submit_addnow");
<i> </i>define("SUBMIT_CANCEL", "submit_cancel");


<i> </i>/**************************************************************************
<i> </i> VARIABLES: LOCAL
<i> </i>**************************************************************************/
<i> </i>$arrPath_CSS = array(PATH_CSS, PATH_CSS_EXTRA);
<i> </i>$arrPath_JS = array(PATH_ROOT . "javascript/class.Validate.js",
<i> </i> PATH_ROOT . "javascript/photo.js");
<i> </i>$arrForm = array();
<i> </i>$arrError = array();
<i> </i>$arrFileUpload = array();
<i> </i>$arrGallery = array();
<i> </i>$intGalleryID = $objSession-&gt;FetchData("GALLERY_DATA");


<i> </i>/**************************************************************************
<i> </i> AUTHENTICATION MODULE
<i> </i>**************************************************************************/
<i> </i>$objAuth = new Authentication();
<i> </i>if(!$objAuth-&gt;Status()) {
<i> </i> header(LOGIN_FAILED);
<i> </i> exit();
<i> </i>}


<i> </i>/**************************************************************************
<i> </i> VALIDATION MODULE
<i> </i>**************************************************************************/
<i> </i>$objValid = new Validate("title", "summary");
<i> </i>$objValid-&gt;Initialize("title", "", 10);
<i> </i>$objValid-&gt;Initialize("summary", "", 10);
<i> </i>$arrForm = $objValid-&gt;BuildForm($_POST);
<i> </i>$arrForm = $objValid-&gt;CleanUp($arrForm);


<i> </i>/**************************************************************************
<i> </i> MySQL DATABASE MODULE
<i> </i>**************************************************************************/
<i> </i>$objDB = new MySQLDB(MySQL_HOST, MySQL_USER, MySQL_PASS);
<i> </i>$objDB-&gt;Open();
<i> </i>$objDB-&gt;SelectDB(MySQL_DB);


<i> </i>/**************************************************************************
<i> </i> FORM VALIDATE: UPLOAD (ADD NOW) PHOTOS
<i> </i>**************************************************************************/
<i> </i>if(isset($_POST[SUBMIT_ADDNOW])) {
<i> </i> $objValid-&gt;Upload("photo", PATH_GALLERY . "/");
<i> </i> $objValid-&gt;ImageType();
<i> </i> if($objValid-&gt;FormStatus()) {
<i> </i> $arrFileUpload = $objValid-&gt;Process();
<i> </i> }

<i> </i> $arrError = $objValid-&gt;BuildErrors();
<i> </i>}


<i> </i>/**************************************************************************
<i> </i> FORM TIMEOUT: UPLOAD (ADD NOW) PHOTOS

<i> </i> Large uploads that exceed the server's allowed limit (post_max_size)
<i> </i> causes the script to reload with these empty globals ($_POST and
<i> </i> $_FILES).
<i> </i>**************************************************************************/
<i> </i>if(isset($_GET["upload"]) &amp;&amp; $_GET["upload"] == "true") {
<i> </i> if($objValid-&gt;Timeout()) {
<i> </i> $arrError = $objValid-&gt;BuildErrors();
<i> </i> }
<i> </i>}


<i> </i>/**************************************************************************
<i> </i> FORM PROCESSING: UPLOAD (ADD NOW) PHOTOS
<i> </i>**************************************************************************/
<i> </i>if(isset($_POST[SUBMIT_ADDNOW]) &amp;&amp; $objValid-&gt;FormStatus()) {
<i> </i> $arrForm = $objValid-&gt;EscapeText($arrForm);

<i> </i> // Select gallery information for which uploaded photos belong to
<i> </i> $objDB-&gt;Query("SELECT size_full, size_thumb, quality, " .
<i> </i> "loc_full, loc_thumb, name " .
<i> </i> "FROM gallery " .
<i> </i> "WHERE id = '$intGalleryID'");
<i> </i> if($objDB-&gt;NumRowsinResult() &gt; 0) {
<i> </i> $arrGallery = $objDB-&gt;FetchRow();
<i> </i> } else {
<i> </i> trigger_error("The gallery selected to upload your images to " .
<i> </i> "could not be found", E_USER_ERROR);
<i> </i> }


<i> </i> for($x = 0; $x &lt; count($arrFileUpload); $x++) {
<i> </i> // Resize photo to "Fullsize" specification
<i> </i> $objValid-&gt;Resize($arrFileUpload[$x]["path"],
<i> </i> $arrGallery[0]["size_full"],
<i> </i> $arrGallery[0]["loc_full"] ."/". $arrFileUpload[$x]["file"],
<i> </i> $arrGallery[0]["quality"]);
<i> </i> // Resize photo to "Thumbnail" specification
<i> </i> $objValid-&gt;Resize($arrFileUpload[$x]["path"],
<i> </i> $arrGallery[0]["size_thumb"],
<i> </i> $arrGallery[0]["loc_thumb"] ."/". $arrFileUpload[$x]["file"]);

<i> </i> // Remove the original uploaded photo
<i> </i> @ unlink($arrFileUpload[$x]["path"]);

<i> </i> // Insert photo information into database
<i> </i> $objDB-&gt;Query("INSERT INTO photo " .
<i> </i> "SET id = null, " .
<i> </i> "galleryid = '$intGalleryID', " .
<i> </i> "filename = '{$arrFileUpload[$x]["file"]}', " .
<i> </i> "title = '{$arrForm["title"][$x]}', " .
<i> </i> "summary = '{$arrForm["summary"][$x]}'");

<i> </i> // Give the script "something to do" in-between photo resizing, as
<i> </i> // otherwise the script will timeout (unable to access PHP.INI info).

<i> </i> }

<i> </i> // Delete/Create session data
<i> </i> $arrTmpData = array("photo" =&gt; count($arrFileUpload), "gallery" =&gt; $arrGallery[0]["name"]);
<i> </i> $objSession-&gt;Delete("GALLERY_DATA");
<i> </i> $objSession-&gt;Create("ADD_PHOTO", true);
<i> </i> $objSession-&gt;Create("ADD_INFO", $arrTmpData);
<i> </i> header("Location:" . PATH_ROOT . "index.php");
<i> </i> exit();
<i> </i>}


<i> </i>/**************************************************************************
<i> </i> FORM PROCESSING: CANCEL UPLOAD (ADD NOW) PHOTOS
<i> </i>**************************************************************************/
<i> </i>if(isset($_POST[SUBMIT_CANCEL])) {
<i> </i> header("Location:" . $objSession-&gt;FetchData("PREV_PAGE"));
<i> </i> exit();
<i> </i>}


<i> </i>/**************************************************************************
<i> </i> TEMPLATE (INNER)
<i> </i>**************************************************************************/
<i> </i>$path = "templates/";
<i> </i>$objTemplate = new Template($path);
<i> </i>$objTemplate-&gt;SetVar("form", $objValid-&gt;UnescapeText($arrForm));
<i> </i>$objTemplate-&gt;SetVar("error", $arrError);


<i> </i>/**************************************************************************
<i> </i> TEMPLATE (SHELL)
<i> </i>**************************************************************************/
<i> </i>$html = "";
<i> </i>$objTemplateShell = new Template($html);
<i> </i>$objTemplateShell-&gt;SetVar("title", " – Photo Gallery – Upload Photos");
<i> </i>$objTemplateShell-&gt;SetVar("css", $arrPath_CSS);
<i> </i>$objTemplateShell-&gt;SetVar("javascript", $arrPath_JS);
<i> </i>$objTemplateShell-&gt;SetVar("body", $objTemplate-&gt;Fetch("gallery_upload.html.php"));
<i> </i>echo $objTemplateShell-&gt;Fetch("templates/html_template.html.php");
?&gt;
×

Success!

Help @badg0003 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...