【问题标题】:max_execution_time not working on only 1 scriptmax_execution_time 仅适用于 1 个脚本
【发布时间】:2014-07-21 17:16:00
【问题描述】:

我已在 .htaccess 中将 max_execution_time 设置为 1200,以便执行我需要执行的脚本。 我 99% 的脚本都能正常工作;但是 1 拒绝运行超过几秒钟。 这是一个执行多个 sql 操作的脚本,但一个类似的脚本只执行第一个插入/添加(带有很多类似的代码)确实有效。

补充:我在共享主机上,然后它工作正常,但切换到私人“容器”后它不再工作了。 在共享主机上,我必须在脚本本身中设置更长的超时时间,升级后更长的超时时间在我的 htaccess 中。

会不会是 .htaccess 以某种奇怪的方式无法在我的脚本上应用/工作,或者是否存在 mysql 错误?我的错误日志什么也没说。正在发送脚本末尾的电子邮件。

php版本为:5.3.28-1。

脚本:

    <?php require_once('../../includes/connect.php');
require_once('../../includes/functions.php');

mysql_select_db($database, $databaseConnect);

// get product feed options  - maybe needed
$getFeedOptions = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'feedOptions' LIMIT 1");
$theFeedOptions = mysql_fetch_assoc($getFeedOptions);
$feedOpts = explode(':',$theFeedOptions['value']);

if (isset($_GET['fd_refresh'])) {


$fdrefresh = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'feedMemory".$_GET['fd_refresh']."'");
$refresh = mysql_fetch_assoc($fdrefresh);

$pieces = explode("-:-", $refresh['value']);

$fdURLfeed = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'csvURL".$_GET['fd_refresh']."'");
$URLfeed = mysql_fetch_assoc($fdURLfeed);
$fdtypeFeed = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'csvType".$_GET['fd_refresh']."'");
$typeFeed = mysql_fetch_assoc($fdtypeFeed);

    if ($typeFeed['value'] == 'tab') {
    $typeFeed = "\t";
    } else {
    $typeFeed = $typeFeed['value'];
    }

// set row variable and open file
$row = intval($pieces[11]);
if ($URLfeed['title'] == 'Upload Feed') {
$handle = fopen('../'.$URLfeed['value'], "r");
} else {
$handle = fopen($URLfeed['value'], "r");
}
// empty the table
$empty = "DELETE FROM affiliSt_products WHERE prodDB IN ('".$_GET['fd_refresh']."')";
mysql_query($empty);

// start auto inc from last ID in db
$autoinc = mysql_query("SELECT prodID FROM affiliSt_products ORDER BY prodDB DESC LIMIT 1");
$autoincnum = mysql_fetch_assoc($autoinc);
$resetautoinc = mysql_query("ALTER TABLE affiliSt_products AUTO_INCREMENT = ".($autoincnum['prodID']+1)."");

// while loop with fgetcsv sorts the csv into the data array 
while (($data = fgetcsv($handle, 6000, $typeFeed)) !== FALSE) {

    $resulta = $pieces[0];
    if ($data[intval($pieces[1])] == NULL) {
    $resultb = $row;
    } else {
    $resultb = $data[intval($pieces[1])];
    }
    switch ($feedOpts[0]) {
        case 0:
            $resultc = ucwords(strtolower($data[intval($pieces[2])]));
            $resultd = ucwords(strtolower($data[intval($pieces[3])]));
            $resulte = ucwords(strtolower($data[intval($pieces[4])]));
            break;
        case 1:
            $resultc = $data[intval($pieces[2])];
            $resultd = $data[intval($pieces[3])];
            $resulte = $data[intval($pieces[4])];
            break;
        case 2:
            if (isset($feedOpts[1]) && $feedOpts[1] == 1) {
                $resultc = ucwords(strtolower($data[intval($pieces[2])]));
            } else {
                $resultc = $data[intval($pieces[2])];
            }
            if (isset($feedOpts[2]) && $feedOpts[2] == 1) {
                $resultd = ucwords(strtolower($data[intval($pieces[3])]));
            } else {
                $resultd = $data[intval($pieces[3])];
            }
            if (isset($feedOpts[3]) && $feedOpts[3] == 1) {
                $resulte = ucwords(strtolower($data[intval($pieces[4])]));
            } else {
                $resulte = $data[intval($pieces[4])];
            }
            break;
        default: //catchall
            $resultc = ucwords(strtolower($data[intval($pieces[2])]));
            $resultd = ucwords(strtolower($data[intval($pieces[3])]));
            $resulte = ucwords(strtolower($data[intval($pieces[4])]));
            break;
    }
    $resultf = $data[intval($pieces[5])];
    $resultg = $data[intval($pieces[6])];
    $resulth = $data[intval($pieces[7])];
    $resulti = $data[intval($pieces[8])];
    $resultj = $data[intval($pieces[9])];
    $resultk = $pieces[10];
    $resultm = $data[intval($pieces[14])];
    $resultn = $data[intval($pieces[15])];
    $resulto = $data[intval($pieces[16])];
    $resultp = $data[intval($pieces[17])];
    $resultq = $data[intval($pieces[18])];
    $resultr = $data[intval($pieces[34])];
    $results = intval($row);

    if ($pieces[12] == 'before') {
    $resulth = $pieces[13].$resulth;
    } else if ($pieces[12] == 'after') {
    $resulth = $resulth.$pieces[13];
    }

// remove characters that may interfear with navigation or display
    include("../../includes/fixlist.inc.php");

    $resultc = str_replace($andAmps, "and", $resultc);
    $resultd = str_replace($andAmps, "and", $resultd);
    $resulte = str_replace($andAmps, "and", $resulte);
    $resultc = str_replace($charquotes, "", $resultc);
    $resultd = str_replace($charquotes, "", $resultd);
    $resulte = str_replace($charquotes, "", $resulte);
    $resultb = str_replace($allCharacters, "-", $resultb);
    $resultc = str_replace($allCharacters, " ", $resultc);
    $resultd = str_replace($someCharacters, " ", $resultd);
    $resulte = str_replace($allCharacters, " ", $resulte);
    $resultj = str_replace($currencyCharacters, " ", $resultj);
    $resultl = $_GET['fd_refresh'];

// miss out headers row
   if ($row != 0) {
   // insert all the data into the database table
        $sql = sprintf("INSERT INTO affiliSt_products (

                merchant,   
                merchantProdID,     
                prodCategory,   
                prodName,   
                prodBrand,  
                prodDescription,    
                prodPromoText,  
                prodLink,   
                prodImageURL,   
                prodPrice, 
                prodCurrency,
                prodDB,
                extraFieldA,
                extraFieldB,
                extraFieldC,
                extraFieldD,
                extraFieldE,    
                prodImageSmall,     
                dbProdID

                ) VALUES (

                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s,
                %s
                )",
                quote_smart($resulta),
                quote_smart($resultb),
                quote_smart($resultc),
                quote_smart($resultd),
                quote_smart($resulte),
                quote_smart($resultf),
                quote_smart($resultg),
                quote_smart($resulth),
                quote_smart($resulti),
                quote_smart($resultj),
                quote_smart($resultk),
                quote_smart($resultl),
                quote_smart($resultm),
                quote_smart($resultn),
                quote_smart($resulto),
                quote_smart($resultp),
                quote_smart($resultq),
                quote_smart($resultr),
                quote_smart($results));
        mysql_query($sql, $databaseConnect) or die(mysql_error());
        }

    $row++;
    }

// create the new config nav
// category listing
$getCategory = mysql_query("SELECT prodCategory FROM affiliSt_products WHERE prodDB = '".$_GET['fd_refresh']."' ORDER BY prodCategory ASC");
$categoryList = mysql_fetch_assoc($getCategory);
$newnavigation = '';
do { 
    if ($feedOpts[0] == 0 || ($feedOpts[0] == 2 && $feedOpts[1] == 1)) {
        $catresult = ucwords(strtolower($categoryList['prodCategory']));
    } else {
        $catresult = $categoryList['prodCategory'];
    }
    if ($storedCategory != $catresult && $catresult != NULL) {
        $newnavigation .= $catresult;
        // start sub nav
        // brand listing
        $getBrands = mysql_query("SELECT prodBrand FROM affiliSt_products WHERE prodDB = '".$_GET['fd_refresh']."' AND prodCategory = '$catresult' ORDER BY prodBrand ASC");
        $brandList = mysql_fetch_assoc($getBrands);
        do {
            if ($feedOpts[0] == 0 || ($feedOpts[0] == 2 && $feedOpts[3] == 1)) {
                $theresult = ucwords(strtolower($brandList['prodBrand']));
            } else {
                $theresult = $brandList['prodBrand'];
            }
            if ($storedBrand != $theresult && $theresult != NULL) {
                $newnavigation .= '(:)'.$theresult;
                $storedBrand = $theresult;
                $brandrow++;
            } else {
                if ($feedOpts[0] == 0 || ($feedOpts[0] == 2 && $feedOpts[3] == 1)) {
                    $theresult = ucwords(strtolower($brandList['prodBrand']));
                } else {
                    $theresult = $brandList['prodBrand'];
                }               
            }
        } while ($brandList = mysql_fetch_assoc($getBrands));
        $storedCategory = $catresult;
        $newnavigation .= '-:-';
    } else {
        if ($feedOpts[0] == 0 || ($feedOpts[0] == 2 && $feedOpts[1] == 1)) {
            $catresult = ucwords(strtolower($categoryList['prodCategory']));
        } else {
            $catresult = $categoryList['prodCategory'];
        }   
    }
} while ($categoryList = mysql_fetch_assoc($getCategory));
$newnavigation = rtrim($newnavigation, '-:-');

$sql= "DELETE FROM affiliSt_config WHERE name='nav".$_GET['fd_refresh']."'" ;        
mysql_query($sql, $databaseConnect) or die(mysql_error());
$insert = array (
        array ( 'name' =>  'nav'.$_GET['fd_refresh'],
                'value' => $newnavigation,
                'comment' => 'Category and subcategory navigation',
                'title' => 'Generated Navigation')
);

// insert values posted from Step 1 into config table
foreach ($insert as $row) {
    $sql = sprintf("INSERT INTO affiliSt_config (
            name, value, comment, title
            ) values (
            %s, %s, %s, %s
            )",
            quote_smart($row['name']),
            quote_smart($row['value']),
            quote_smart($row['comment']),
            quote_smart($row['title']));
    mysql_query($sql, $databaseConnect) or die(mysql_error());
}
// end config nav



// get config details
$getMyEmail = mysql_query("SELECT * FROM affiliSt_config WHERE name = 'adEmail'");
$myEmail = mysql_fetch_assoc($getMyEmail);

// new link email
$myemailaddress = $myEmail['value'];
$emailaddress = $myemailaddress;
$subject = $pieces[0]." Cron Just Updated";
$emailmessage = $emailNew['value'];
$emailfrom = $myemailaddress;
$messageb .= "Dear Admin\n\n".$pieces[0]." cron just updated"."\n\n";
$runtime = (date("d M Y H:i"));
$messageb .= "Time of the message: $runtime (server time zone)\n\n";
mail($emailaddress, $subject, $messageb, "From: $emailfrom");

}
?>

【问题讨论】:

  • 请考虑发布错误的脚本,我们必须帮助您:)
  • 是否有另一个 .htaccess 可能会覆盖原始值?
  • 您确定它正在运行并且没有因未显示的错误而崩溃吗?检查您的日志!
  • 感谢您的所有回复;没有其他 .htaccess 推翻主要的(以确保我将主要的复制到目标文件夹)。脚本没有崩溃;完成后,它应该发送一封电子邮件,并且仍然如此。所以它看起来像最大执行时间。

标签: php .htaccess


【解决方案1】:

我在使用 curl 脚本时遇到了同样的问题。我尝试了 ini set 和 set_time_limit 但它仍然没有工作超过 3-10 分钟。所以在我从终端运行它之后,它就像一个魅力。如果可以,您可以将其作为终端命令或通过 cron 作业执行,例如:

php path-to-file/file.php

【讨论】:

  • 感谢您的提示;刚刚将它添加到我的 cron 中两次;一个有php命令,一个没有,现在我们等着看它是否有效。
  • Cron 也不起作用(很可能是因为参数没有通过脚本传递。
【解决方案2】:

我以前没有经历过这样的事情..在参考了一些链接后我找到了解决方案..

safe mode中使用php并尝试下面的代码

if( !ini_get('safe_mode') ){ 
set_time_limit(0); //this won't work if safe_mode is enabled.
}

here找到这个。

【讨论】:

  • 安全模式下的php不允许更改时间限制?但是我尝试了代码,它不起作用......
猜你喜欢
  • 1970-01-01
  • 2020-04-27
  • 2022-08-19
  • 2016-01-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多