Forum Moderators: coopster

Message Too Old, No Replies

script dying...

         

netfiends

11:23 pm on Jul 2, 2005 (gmt 0)

10+ Year Member



I'm doing a script that is falling short before finishing. I have set_time_limit(0); I output an html comment every 10 seconds and it still doesn't finish running... Any ideas?

maxi million

9:30 am on Jul 4, 2005 (gmt 0)

10+ Year Member



loops?

netfiends

9:59 am on Jul 4, 2005 (gmt 0)

10+ Year Member



There are loops. The script basically uploads a file, cuts up the data into (2) different arrays then runs through them to import them into mysql after sorting them... It's dying after the first array.

maxi million

10:27 am on Jul 4, 2005 (gmt 0)

10+ Year Member



may be you could try with 2 or 3 arrays to begin with. check if that is working. if not then theres something going wrong with the loop.

SeanW

12:40 pm on Jul 4, 2005 (gmt 0)

10+ Year Member



Check your web server's error log... You could be exceeding a memory quota. php.ini sets several limits...

Sean

jatar_k

4:53 pm on Jul 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I imagine you are just exceeding the max_execution_time

from
[ca.php.net...]

Set the number of seconds a script is allowed to run. If this is reached, the script returns a fatal error. The default limit is 30 seconds or, if it exists, the max_execution_time value defined in the php.ini. If seconds is set to zero, no time limit is imposed.

When called, set_time_limit() restarts the timeout counter from zero. In other words, if the timeout is the default 30 seconds, and 25 seconds into script execution a call such as set_time_limit(20) is made, the script will run for a total of 45 seconds before timing out.

Warning

set_time_limit() has no effect when PHP is running in safe mode. There is no workaround other than turning off safe mode or changing the time limit in the php.ini.

so, is safe_mode enabled on your site?
It also really seems strange that if you set it to 0 it would override the ini settings.

netfiends

6:22 pm on Jul 4, 2005 (gmt 0)

10+ Year Member



The script works fine with smaller files. There doesn't appear to be an error log of what's happening. I've also had set_time_limit() to 1800 which is like 30mins or so but dies less than (5). I've also tried to allocate more memory via ini_set(memory_limit, "32M"). ignore_user_abort(TRUE) is also set. I dunno if the server is in safe mode or not.

jatar_k

6:28 pm on Jul 4, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



is it a shared host?

to check safe mode use
[php.net...]
then look for safe_mode

netfiends

6:48 pm on Jul 4, 2005 (gmt 0)

10+ Year Member



Yes; it is a shared host. I cannot check if it was in safe mode as I'm changing hosts to see if that solves the problem...

netfiends

7:21 pm on Jul 5, 2005 (gmt 0)

10+ Year Member



Okay; on my new host it's shared and safe mode is disabled.

jatar_k

8:07 pm on Jul 5, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



and does it work?

netfiends

8:35 pm on Jul 5, 2005 (gmt 0)

10+ Year Member



No. It's still not finishing... Would opening a socket to this make a difference? Like having another page open a socket to it or CURL it...

coopster

9:55 am on Jul 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Have you got error_reporting [php.net] turned up so you can see any and all error messages?

netfiends

5:07 pm on Jul 6, 2005 (gmt 0)

10+ Year Member



Okay, I turned error reporting on to: error_reporting(E_ALL) and got the following error:

Notice: Undefined index: the line it refers to is:

$array[$check_id];

and is set earlier as:

$array[$cat_id] = array();

I also have the array ksorted and reset after it is fully set.

coopster

6:45 pm on Jul 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



That means that whatever value is in $check_id is not a key (index) in the $array array. Resolve that issue and try again.

netfiends

2:11 am on Jul 7, 2005 (gmt 0)

10+ Year Member



" That means that whatever value is in $check_id is not a key (index) in the $array array. Resolve that issue and try again."

$check_id is a key in index... Am I mistaken to believe that an array values can be gotten with a variable as the key? $array[$var] or what? I'm doing that and it's working sometimes and other times it isn't...

netfiends

4:04 am on Jul 7, 2005 (gmt 0)

10+ Year Member



What confuses me is that it works flawlessly on smaller files but dies on the larger ones...

netfiends

9:43 am on Jul 7, 2005 (gmt 0)

10+ Year Member



For some reason my upload file is now failing. I have:

define('ROOT', dirname(__FILE__) ."/");
$file_info = ROOT ."tmp/". $_FILES['import_data']['name'];
if(move_uploaded_file($_FILES['import_data']['tmp_name'], $file_info)){

}

Errors:

Warning: move_uploaded_file(data.txt): failed to open stream: Permission denied in script.php on line 8
[Line #8 is the if statement]

Warning: move_uploaded_file(): Unable to move '/tmp/phpyCNIoo' to '{path}/data.txt' in script.php on line 8

Any idea why this is happening? This part used to work on my other server...

netfiends

10:09 am on Jul 7, 2005 (gmt 0)

10+ Year Member



Nevermind about the upload; forgot to chmod the dir to 777

coopster

6:14 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




Am I mistaken to believe that an array values can be gotten with a variable as the key? $array[$var] or what? I'm doing that and it's working sometimes and other times it isn't...

No, you are correct. But the key (index) is non-existent in this case so you need to check for it. Take this example:

error_reporting(E_ALL); 
$array = array(
'index1' => 'value1',
'index2' => 'value2',
'index3' => 'value3'
);
$index = 'index2';
print $array[$index]; // prints value2
unset($array[$index]);
print $array[$index]; // throws NOTICE error
Somewhere your index is no longer defined, if it ever was at all.

netfiends

6:57 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



>> Somewhere your index is no longer defined, if it ever was at all

It *should* still be set because it is all set at the time. I have a (2) sub arrays and a big one of the sub's combined...

[edited by: jatar_k at 6:59 pm (utc) on July 7, 2005]
[edit reason] removed full quote of coop's post [/edit]

netfiends

7:00 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



The code is:

$main_cats = array();
$sub_cats = array();
$categories = array();
foreach($cats_array as $content){
$content = str_replace("INSERT INTO C", "", $content);
$content = explode("VALUES", $content);
$tmp_names = $content['0'];
$tmp_names = str_replace("`", "", $tmp_names);
$tmp_names = explode(",", $tmp_names);
$content = trim($content['1']);
$content = explode(",", $content);

$names = array();
foreach($tmp_names as $key => $value){
$value = trim($value);
$names[$value] = $content[$key];
}
$cat_id = trim($names['id']);
if($cat_id){
if(($names['parent'] === "0") ¦¦ (!$names['parent'])){
$main_cats[$cat_id] = array("id" => "{$names['id']}", "name" => "{$names['name']}", "parent" => "{$names['parent']}", "rank" => "{$names['rank']}");
}else{
$sub_cats[$cat_id] = array("id" => "{$names['id']}", "name" => "{$names['name']}", "parent" => "{$names['parent']}", "rank" => "{$names['rank']}");
}
$categories[$cat_id] = array("id" => "{$names['id']}", "name" => "{$names['name']}", "parent" => "{$names['parent']}", "rank" => "{$names['rank']}");
}
}

ksort($main_cats);
reset($main_cats);
ksort($sub_cats);
reset($sub_cats);
ksort($categories);
reset($categories);

$categories = $main_cats + $sub_cats... There doesn't seem to be an issue/error with this part and as you may or may not be able to see I'm only using stuff that is set in the arrays...

coopster

7:01 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The server doesn't lie ;)


Notice: Undefined index: the line it refers to is:

$array[$check_id];

and is set earlier as:

$array[$cat_id] = array();

One thing I did notice in your earlier post is that your index is defined as two different variables. You say that the index was set earlier with $cat_id when the error is referring to $check_id.

netfiends

7:05 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



I have it named a different variable but it contains the same info...

coopster

7:15 pm on Jul 7, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I get an error earlier on up, Invalid argument supplied for foreach()

It is this line ...

foreach($cats_array as $content){

You don't have a $cats_array defined.

netfiends

8:17 pm on Jul 7, 2005 (gmt 0)

10+ Year Member



Yeah I do, I just hadn't posted that part, the part that gets cats is:

$file_contents = implode('', file($_SESSION['import_path']));
$file_contents = explode("\n", $file_contents);

$import_data = array();
for($i=0; $i <= 60; $i++){
$content = trim($file_contents[$i]);
if($content){
$import_data[] = $content;
}
unset($file_contents[$i]);
}
$line_count = count($file_contents);
$file_contents = implode("\n", $file_contents);
$file_fp = fopen($file_info, "w");
fwrite($file_fp, $file_contents);
fclose($file_fp);

$links_array = array();
$cats_array = array();
foreach($import_data as $content){
$content = trim($content);
if($content){
if(strpos($content, 'INSERT INTO C')!== false){
$content = str_replace("'", "", $content);
$cats_array[] = $content;
}elseif(strpos($content, 'INSERT INTO L')!== false){
$links_array[] = $content;
}
}
}

The script is supposed to upload a user .txt file, break it up into certain areas and proccess the data...