我已经在.htaccess中设置了1200的max_execution_time,用于我需要执行的脚本。 我99%的脚本都能正常工作;但是1拒绝运行超过几秒钟。 这是一个执行多个sql操作的脚本,但是只执行第一次插入/添加(具有大量类似代码)的类似脚本才有效。
补充:我在共享托管,然后它工作正常,但切换到prive"容器"它不起作用了。 在共享主机上我不得不在脚本本身设置更长的超时时间,升级后更长的超时是在我的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");
}
?>
答案 0 :(得分:0)
卷曲脚本遇到了同样的问题。我尝试了ini set和set_time_limit,但它仍然没有工作超过3-10分钟。所以在我从一个终端运行它后,它就像一个魅力。如果可以,您可以将其作为终端命令或通过cron作业来执行:
php path-to-file/file.php
答案 1 :(得分:0)
我之前没有经历过这样的经历。在推荐某人链接后,我找到了解决方案..
在safe mode
中使用php并尝试以下代码
if( !ini_get('safe_mode') ){
set_time_limit(0); //this won't work if safe_mode is enabled.
}
从here找到了这个。