Versio

Cronjob error undefined offset

Overzicht Reageren

Daniel Voogsgerd

Daniel Voogsgerd

04/10/2009 11:21:00
Quote Anchor link
hoi allemaal,
ik ben bezig met een cronjob die alle id´s in runescape opzoekt en aan een name koppelt. Nu werkt het allemaal in een verbazingwekkende snelheid. Alleen sommige items. Worden na de scan niet toegevoegd in de database.

Edit: ben er achter gekomen dat het de onderste error is(zie lijst errors) op lijn 15 dus alleen snap ik niet wat er mis is met die regel.

Errors:
Errors:
Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's robe')' at line 1 insert query.

Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'eggs')' at line 1 insert query

Notice: Undefined offset: 1 in C:\xampp\htdocs\index.php on line 15

config.php
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$getallen
= range(0, 1000);
$cfg['threads'] = 10;
$cfg['timeout'] = 30;

//eventuele functies
function mtime(){
      $mtime = microtime();
      $mtime = explode(" ", $mtime);
      $mtime = $mtime[1] + $mtime[0];
      return $mtime;
}

?>



index.php
Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
require('mysql.php');
require('config.php');
$start = mtime();
echo "<UL>\n";
echo "<li>Update started at ".date("H:i:s")."<li>Start: finding id´s and names.</li>\n<ul>\n";
flush();
function
name_id($data){
$begin = '<div class="brown_box main_ge_page vertically_spaced">'."\n".'<div class="subsectionHeader">';
$eind = '</div>';
if (preg_match("/Error/i",$data)){
        $result = "Bestaat niet";
    }
else{
        $exploded = explode($begin,$data);
        $exploded = explode($eind,$exploded[1]);
        $result = str_replace('<br />','',nl2br($exploded[0]));
    }

    return trim($result);
}

$cURL_done = 0;
$cURL_last = 0;
$MySQL_done = 0;
$MySQL_last = 0;
// Urls to download
$urls = array();
foreach ($getallen as $value){
    $urls[] = 'http://itemdb-rs.runescape.com/viewitem.ws?obj='.$value;
}



    $mcurl = curl_multi_init();
    $threadsRunning = 0;
    $urls_id = 0;
for(;;) {
        //de vrije ruimtes vullen
        while ($threadsRunning < $cfg['threads'] && $urls_id < count($urls)) {
            //echo 'Adding download link: '.$urls[$urls_id].'<br>';
            //flush();

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_TIMEOUT, $cfg['timeout']);
            curl_setopt($ch, CURLOPT_URL, $urls[$urls_id++]);
            curl_multi_add_handle($mcurl, $ch);
            $threadsRunning++;
        }

        //Als hij klaar is
        if ($threadsRunning == 0 && $urls_id >= count($urls))
        break;
        
        //cURL
        curl_multi_select($mcurl);
        while(($mcRes = curl_multi_exec($mcurl, $mcActive)) == CURLM_CALL_MULTI_PERFORM) usleep(100000);
        if($mcRes != CURLM_OK) break;
        while($done = curl_multi_info_read($mcurl)) {
            $ch = $done['handle'];
            $done_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
            $done_content = curl_multi_getcontent($ch);
            
            if(curl_errno($ch) == 0) {
                //output als er geen errors zijn
                $id = array_search($done_url, $urls);
                $id_name[$id]= name_id($done_content);
                $cURL_done++;
                $cURL_perCent = round($cURL_done / count($urls) * 100);
                $cURL_perDecem = floor($cURL_perCent / 10) * 10;
                if($cURL_last != $cURL_perDecem){
                    echo '<li>'.$cURL_perDecem.'% of the id´s and names found at '.date("H:i:s")."</li>\n";
                    $cURL_last = $cURL_perDecem;
                }

                flush();
                }
else {
                    //output als er een error is
                    echo 'cURL error:'.curl_error($ch);
                    flush();
                }

                    curl_multi_remove_handle($mcurl, $ch);
                    curl_close($ch);
                    $threadsRunning--;
        }
    }

curl_multi_close($mcurl);
echo "</ul>\n<li>Completed: finding id´s and names at ".date("H:i:s")."</li>\n<li>Start: Sorting id´s and names.</li>\n";
ksort($id_name);
echo "<li>Completed: Sorting id´s and names at ".date("H:i:s")."</li>\n<li>Start: Deleting old data from the database.</li>\n";
flush();
//de delete query
$query1 = "DELETE FROM IDlist";
$deletedatabase = mysql_query($query1, $link);
if (!$deletedatabase) {
    echo "Error, Could mot delete the database\n";
    echo 'MySQL Error: ' . mysql_error();
    exit;
}


echo "<li>Completed: Deleting old data from the database at ".date("H:i:s")."</li>\n<li>Start: Putting id´s and names into the database.</li>\n<ul>\n";
flush();
//de insert query
foreach($id_name as $id => $name){
    if($name != "Bestaat niet"){
        $sql = ("INSERT INTO idlist (ID, Name) VALUES ('".$id."', '".$name."')");
        if(!mysql_query($sql, $link)){
            echo $id." Error: ".MySQL_error()." insert query";    
        }
    }

    $MySQL_done++;
    $MySQL_perCent = round($MySQL_done / count($urls) * 100);
    $MySQL_perDecem = floor($MySQL_perCent / 10) * 10;
    if($MySQL_last != $MySQL_perDecem){
        echo '<li>'.$MySQL_perDecem.'% of the id´s and names are inserted at '.date("H:i:s")."</li>\n";
        $MySQL_last = $MySQL_perDecem;
    }
}

echo "</ul>\n<li>Completed: Putted id´s and names into the database.".date("H:i:s")."</li>\n<li>Checks all information.</li>\n";
flush();


//controle of alles goed is.
$selectquery = "SELECT * FROM idlist WHERE name=''";
$select = mysql_query($selectquery, $link);
if(!$select){
            echo "Error:".MySQL_error()." controle";    
        }
else{
$row = mysql_fetch_array($select);
$num_rows = mysql_num_rows($select);
echo "<ul>\n<li>There are ".$num_rows." Empty fields</li>\n";
flush();
if($num_rows > 0){
    echo "<ul>\n<li>Start: Finding id's and name's and put them into the database</li>\n<ul>\n";
    while($row = mysql_fetch_assoc($select)){
        echo "<li>".$row['ID']."</li>\n";
    }

    echo "</ul>\n";
}

echo "</ul>\n";

}


//De tijd
$eind = mtime();
$tijd = "";
$totaltime = ($eind - $start);
$seconds = floor($totaltime);
$seconds2 = floor($totaltime);
$minutes = floor($seconds / 60);
$hours = floor($seconds / 3600);

if($seconds > 0){
$tijd .= $seconds.' seconds ';
}

if($minutes > 0){
$tijd .= $minutes.' minutes ';
$seconds = $seconds - ($minutes * 60);
}

if($hours > 0){
$tijd .= $hours.' hours ';
$minutes = $minutes - ($hours * 60);
}

echo "<li>Script completed at ".date("H:i:s")."</li>\n</ul>\n";
echo "<li>Scanned and inserted ".count($getallen)." items in ".$tijd."</li>\n";
echo "<li>That´s ".$seconds2 / count($getallen)." seconds per item.</li>\n";






//echo "<pre>";
//print_r($cfg);
//print_r($MySQL);
//print_r($id_name);
//echo "</pre>";

?>
Gewijzigd op 01/01/1970 01:00:00 door Daniel Voogsgerd
 
PHP hulp

PHP hulp

24/05/2012 07:25:04
Gesponsorde koppelingen:
BHosted Hosting al vanaf € 1,- per maand

Controleer nu gratis jouw domeinnaam:

  
 
Er zijn nog geen reacties op dit bericht.



Overzicht Reageren