te veel processes/request
Helaas loop ik met mijn website tegen het probleem aan dat er teveel processes geladen worden, waardoor de website niet meer bereikbaar is.
Ik gebruik joomla en maak gebruik van een affiliatefeed component en laadt de volgende template in voor een dagaanbieding (zie code beneden).
Op de homepagina staan zo'n 100 aanbiedingen, er wordt dus 100x onderstaand template geladen.
Ligt het hieraan? dient deze geoptimaliseerd te worden ?
Op een enkele pagina zijn dat er 250 (processes).
Nu lijkt mijn server (virtual/shared) dit niet aan te kunnen.
De specs van de server zijn:
2 x Intel Xeon E5506, Nehalem 2.13Ghz Quad Core, 4.8GT/s, 4MB, 32/64 bit
48GB DDR-3 6 x Kingston 8192MB DDR-3
4 x Western Digital 1000GB, SATA II, 64MB, 7200rpm, raid edition
Tevens heb ik alle overbodige plugins in Joomla uitgezet.
Zie hieronder een screenshot van de processes:
Wie o wie kan mij helpen?
http://tinypic.com/r/wrmjo4/6
Code:
Code (php)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<?php // no direct access
defined('_JEXEC') or die('Restricted access');
echo '<div id="left" ><jdoc:include type="modules" name="left" style="xhtml" /></div>';
echo '<div id="com_datafeeds">';
if ( $this->where['qt'] ) {
echo $this->loadTemplate('full');
} else {
$currency=$this->where['currency_sign'];
if ($this->pagination ) {
$links= $this->pagination->getPagesLinks();
echo '<div class="pagination" id="datafeeds_top">'.$links.'</div>';
}
echo '<div class="datafeeds_clear">';
foreach ($this->dataitems as $item ) {
$product_title=$item['title'];
$product_id=$item['items_id'];
$alt=df_alt($item['title']);
#point to detailed information
$product_url=JRoute::_( $this->where['baselink']."&". make_urlencoded(array("qt"=>$product_title)));
#point to merchant
$product_ref=$item['url'];
$product_price=$item['Prijs'];
$product_image=$item['image'];
########## 5 sept
$link=JRoute::_("$baselink&" . make_urlencoded(array("qt"=>$item['title'])));
$korting=number_format(($item['Select5']-$item['Prijs'])/($item['Select5']/100),0);
print '<div class="df_3col_container">';
#logo#
print '<div class="df_3col_logo" ><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow" ><img src="http://www.mijnwebsiteurl.nl/img/'.str_replace(' ','_',$item['feed']).'.jpg" width="190px" height="45px" alt="Dagaanbiedingen van '.$item['feed'].'" /></a></div>';
#product actieprijs#
if ($product_price > 0 ) {
print '<p class="df_3col_prijs"><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">'.
$currency.''.money_format('%!.2n', $product_price).
'</a></p>';
} else {
print '<p class="df_3col_prijs"><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">GRATIS!</a></p>';
}
#afbeelding#
print '<div class="df_3col_img" ><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow"><img src="http://imgc.mijnwebsiteurl.nl/'.$item['feed_id'].'/'.$item['items_id'].'.jpg" width="216px" alt="'.$product_title.'" '.$this->geen_img_script.'/></a></div>';
#titel product#
print '<div class="df_3col_list_title"><h2 class="df_3col_list_title"><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow" >'.$product_title.'</a></h2></div>';
echo '<div class="info">';
#normale prijs product#
if ($item['Select5'] > 0 ) {
echo '<div class="normaleprijs">'.$currency.''.money_format('%!.2n', $item['Select5']).'</div>';
} else {
print ' ';
}
#van voor prijs#
if ($item['Select5'] > 0 ) {
echo '<div class="normaleprijsopsomming"><ul><li>Van: <font style=" text-decoration:line-through; font-weight:bold; color:#cc0000;"> '.$currency.' '.money_format('%!.2n', $item['Select5']).'</font> voor: <font style="font-weight:bold; color:#000;"> '.
$currency.' '.money_format('%!.2n', $product_price).' </font></li></ul></div>';
} else {
print '<div class="normaleprijsopsomming"><ul ><li>Actieprijs: <font style="font-weight:bold; color:#000;">'.
$currency.' '.money_format('%!.2n', $product_price).' </font></li></ul></div> ';
}
echo ' <div align="right" style="margin:2px; float:right;"> ';
if ($item['Select5'] > 0 ) {echo '<a href="http://twitter.com/home?status='.$item['title'].'. Van '.$item['Select5'].' Voor '.$product_price.', '.$korting.'procent korting op www.mijnwebsiteurl.nl" title="Deel op Twitter" target="_blank"><img src="templates/mijnwebsiteurl/images/Twitter-icon.png" alt="Deel mijnwebsiteurl.nl op Twitter" width="18" height="18"></a></div>'; } else {
print '<a href="http://twitter.com/home?status='.$item['title'].'. Actieprijs van '.$product_price.' op www.mijnwebsiteurl.nl" title="Deel op Twitter" target="_blank"><img src="templates/mijnwebsiteurl/images/Twitter-icon.png" alt="Deel mijnwebsiteurl.nl op Twitter" width="18" height="18"></a></div>';
}
#korting#
if ($item['Select5'] > 0 ) {
echo '<div class="normaleprijsopsomming"><ul><li><font style="font-weight:bold; color:#000;"> '.$korting.'% korting </font></li></ul></div>';
} else {
print ' ';
}
#tijd verzending#
if ($item['Select6'] > 0 ) {
echo '<div class="timetoship"><ul><li><!--Verzending:--> '.$item['Select6'].'</li></ul></div>';
} else {
print ' ';
}
#aanbieder#
if ($item['Select7'] > 0 ) {
echo '<div class="aanbieder"><ul><li><!--Meer informatie op: --><a class="dflink" target="_blank" href="'.$product_url.'" rel="nofollow"> '.$item['Select7'].'</a></li></ul></div>';
} else {
print '<div class="aanbieder"><ul><li><!--Meer informatie op: --><a class="dflink" target="_blank" href="'.$product_url.'" rel="nofollow"> '.$item['feed'].'</a></li></ul></div> ';
}
#actie tot#
if ($item['Select8'] == 8) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow"> 8:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 9) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">9:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 10) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">10:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 12 ) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">12:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 24 ) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">0:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 000) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">0:00 uur </a></li></ul></div>';
} else {
print ' ';
}
echo '</div>';
print'</div>';
}
print '</div><div class="datafeeds_clear datafeeds_fix"> </div>';
if ($this->pagination ) {
echo '<div class="pagination" id="datafeeds_bottom">'.$links.'</div>';
}
}
echo '</div>';
defined('_JEXEC') or die('Restricted access');
echo '<div id="left" ><jdoc:include type="modules" name="left" style="xhtml" /></div>';
echo '<div id="com_datafeeds">';
if ( $this->where['qt'] ) {
echo $this->loadTemplate('full');
} else {
$currency=$this->where['currency_sign'];
if ($this->pagination ) {
$links= $this->pagination->getPagesLinks();
echo '<div class="pagination" id="datafeeds_top">'.$links.'</div>';
}
echo '<div class="datafeeds_clear">';
foreach ($this->dataitems as $item ) {
$product_title=$item['title'];
$product_id=$item['items_id'];
$alt=df_alt($item['title']);
#point to detailed information
$product_url=JRoute::_( $this->where['baselink']."&". make_urlencoded(array("qt"=>$product_title)));
#point to merchant
$product_ref=$item['url'];
$product_price=$item['Prijs'];
$product_image=$item['image'];
########## 5 sept
$link=JRoute::_("$baselink&" . make_urlencoded(array("qt"=>$item['title'])));
$korting=number_format(($item['Select5']-$item['Prijs'])/($item['Select5']/100),0);
print '<div class="df_3col_container">';
#logo#
print '<div class="df_3col_logo" ><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow" ><img src="http://www.mijnwebsiteurl.nl/img/'.str_replace(' ','_',$item['feed']).'.jpg" width="190px" height="45px" alt="Dagaanbiedingen van '.$item['feed'].'" /></a></div>';
#product actieprijs#
if ($product_price > 0 ) {
print '<p class="df_3col_prijs"><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">'.
$currency.''.money_format('%!.2n', $product_price).
'</a></p>';
} else {
print '<p class="df_3col_prijs"><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">GRATIS!</a></p>';
}
#afbeelding#
print '<div class="df_3col_img" ><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow"><img src="http://imgc.mijnwebsiteurl.nl/'.$item['feed_id'].'/'.$item['items_id'].'.jpg" width="216px" alt="'.$product_title.'" '.$this->geen_img_script.'/></a></div>';
#titel product#
print '<div class="df_3col_list_title"><h2 class="df_3col_list_title"><a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow" >'.$product_title.'</a></h2></div>';
echo '<div class="info">';
#normale prijs product#
if ($item['Select5'] > 0 ) {
echo '<div class="normaleprijs">'.$currency.''.money_format('%!.2n', $item['Select5']).'</div>';
} else {
print ' ';
}
#van voor prijs#
if ($item['Select5'] > 0 ) {
echo '<div class="normaleprijsopsomming"><ul><li>Van: <font style=" text-decoration:line-through; font-weight:bold; color:#cc0000;"> '.$currency.' '.money_format('%!.2n', $item['Select5']).'</font> voor: <font style="font-weight:bold; color:#000;"> '.
$currency.' '.money_format('%!.2n', $product_price).' </font></li></ul></div>';
} else {
print '<div class="normaleprijsopsomming"><ul ><li>Actieprijs: <font style="font-weight:bold; color:#000;">'.
$currency.' '.money_format('%!.2n', $product_price).' </font></li></ul></div> ';
}
echo ' <div align="right" style="margin:2px; float:right;"> ';
if ($item['Select5'] > 0 ) {echo '<a href="http://twitter.com/home?status='.$item['title'].'. Van '.$item['Select5'].' Voor '.$product_price.', '.$korting.'procent korting op www.mijnwebsiteurl.nl" title="Deel op Twitter" target="_blank"><img src="templates/mijnwebsiteurl/images/Twitter-icon.png" alt="Deel mijnwebsiteurl.nl op Twitter" width="18" height="18"></a></div>'; } else {
print '<a href="http://twitter.com/home?status='.$item['title'].'. Actieprijs van '.$product_price.' op www.mijnwebsiteurl.nl" title="Deel op Twitter" target="_blank"><img src="templates/mijnwebsiteurl/images/Twitter-icon.png" alt="Deel mijnwebsiteurl.nl op Twitter" width="18" height="18"></a></div>';
}
#korting#
if ($item['Select5'] > 0 ) {
echo '<div class="normaleprijsopsomming"><ul><li><font style="font-weight:bold; color:#000;"> '.$korting.'% korting </font></li></ul></div>';
} else {
print ' ';
}
#tijd verzending#
if ($item['Select6'] > 0 ) {
echo '<div class="timetoship"><ul><li><!--Verzending:--> '.$item['Select6'].'</li></ul></div>';
} else {
print ' ';
}
#aanbieder#
if ($item['Select7'] > 0 ) {
echo '<div class="aanbieder"><ul><li><!--Meer informatie op: --><a class="dflink" target="_blank" href="'.$product_url.'" rel="nofollow"> '.$item['Select7'].'</a></li></ul></div>';
} else {
print '<div class="aanbieder"><ul><li><!--Meer informatie op: --><a class="dflink" target="_blank" href="'.$product_url.'" rel="nofollow"> '.$item['feed'].'</a></li></ul></div> ';
}
#actie tot#
if ($item['Select8'] == 8) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow"> 8:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 9) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">9:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 10) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">10:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 12 ) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">12:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 24 ) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">0:00 uur </a></li></ul></div>';
} else {
print ' ';
}
if ($item['Select8'] == 000) {
echo '<div class="actietijd"><ul><li>Actie geldig tot: <a class="dflink" target="_blank" href="'.$product_ref.'" rel="nofollow">0:00 uur </a></li></ul></div>';
} else {
print ' ';
}
echo '</div>';
print'</div>';
}
print '</div><div class="datafeeds_clear datafeeds_fix"> </div>';
if ($this->pagination ) {
echo '<div class="pagination" id="datafeeds_bottom">'.$links.'</div>';
}
}
echo '</div>';
Waarschijnlijker is dat je tegen een geheugenlimiet aanloopt. Dat kun je testen door op kritieke punten het geheugengebruik te echoën.
Verder is dit script inderdaad nog wel wat te optimaliseren. Vervang om te beginnen print door echo. En echo niet met een punt, maar een komma.
Antwoord is: 320920
Ik maak gebruik van 404-image maar ik zie met firephp dat hij een error aangeeft:
"NetworkError: 508 Loop Detected - img.localhost.nl/9/42005.jpg"
Toevoeging op 19/03/2013 13:24:47:
Ward van der Put op 19/03/2013 13:05:14:
Vervang om te beginnen print door echo. En echo niet met een punt, maar een komma.
Ik heb alle prints vervangen door echo...
Alleen wat bedoel je met punt > komma?
Bedoel je dit:
echo '<div class="pagination" id="datafeeds_bottom">'.$links.'</div>';
}
naar
echo '<div class="pagination" id="datafeeds_bottom">',$links,'</div>';
}
Met de puntoperator in echo $a . $b voeg je $a en $b eerst samen tot een nieuwe string, maar die operatie is bij echo overbodig: echo $a, $b is marginaal efficiënter.
Ward van der Put op 19/03/2013 13:31:12:
Met de puntoperator in echo $a . $b voeg je $a en $b eerst samen tot een nieuwe string, maar die operatie is bij echo overbodig: echo $a, $b is marginaal efficiënter.
Helaas rijkt mijn php verstand niet zo ver (en de terminologie ook niet) :(
Weet niet of je ziet waar de loop is?
In php script of kan dit te maken hebben met een onjuist aangemaakte subdomein of iets dergelijks?
1. Een afbeelding wordt niet gevonden en triggert een 404.
2. Die 404 moet een 404-afbeelding tonen, maar die wordt niet gevonden en triggert een volgende 404.
De beste oplossing is dan natuurlijk de 404 voorkomen met afbeeldingen op de juiste locatie.
Toevoeging op 19/03/2013 14:19:23:
Ward van der Put op 19/03/2013 13:55:27:
Naar de loop kan ik alleen raden. Het klinkt alsof je zoiets hebt:
1. Een afbeelding wordt niet gevonden en triggert een 404.
2. Die 404 moet een 404-afbeelding tonen, maar die wordt niet gevonden en triggert een volgende 404.
De beste oplossing is dan natuurlijk de 404 voorkomen met afbeeldingen op de juiste locatie.
1. Een afbeelding wordt niet gevonden en triggert een 404.
2. Die 404 moet een 404-afbeelding tonen, maar die wordt niet gevonden en triggert een volgende 404.
De beste oplossing is dan natuurlijk de 404 voorkomen met afbeeldingen op de juiste locatie.
Maar als je de url/locatie van de afbeelding intypt dan laadt hij wel de afbeelding zien?
Client-side zie ik helaas/gelukkig geen fouten. Een audit in Google Chrome noemt wel wat verbeterpunten, maar de site is lekker snel.
Alleen laadtijd is soms 18sec.
Dat komt dus wellicht door de issue van de 404-image zie ik.
Hij geeft 108 fouten (508 loop fouten weer) met Firephp (firefox addon).
Deze zou ik graag opgelost willen hebben.
Eventueel geef ik er een fooitje voor :)
Info:
Ik heb een subdomein waar de afbeeldingen opgeslagen worden...
Dir: public_html/m/img/[nummer]
Dir: public_html/m
Subdomein: m.domeinnaam.nl
.htaccess alsvolgt:
Code (php)
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
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
Rewriteengine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php
# BEGIN Expire headers
ExpiresActive On
ExpiresDefault "now"
# Configure mime expires
ExpiresByType image/jpeg "access plus 1 month"
<FilesMatch "\.(jpe?g)$">
ExpiresDefault "access plus 1 month"
Header set Pragma "public"
Header append Cache-Control "public, must-revalidate, proxy-revalidate"
</FilesMatch>
# Turn off the ETags
Header unset ETag
FileETag None
# Turn off Last Modified Header
Header unset Last-Modified
<FilesMatch ".(jpg|png|gif)$">
ErrorDocument 404 "/img/noimage.jpg"
</FilesMatch>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) index.php
# BEGIN Expire headers
ExpiresActive On
ExpiresDefault "now"
# Configure mime expires
ExpiresByType image/jpeg "access plus 1 month"
<FilesMatch "\.(jpe?g)$">
ExpiresDefault "access plus 1 month"
Header set Pragma "public"
Header append Cache-Control "public, must-revalidate, proxy-revalidate"
</FilesMatch>
# Turn off the ETags
Header unset ETag
FileETag None
# Turn off Last Modified Header
Header unset Last-Modified
<FilesMatch ".(jpg|png|gif)$">
ErrorDocument 404 "/img/noimage.jpg"
</FilesMatch>
De index.php in de subdirectory is alsvolgt:
Code (php)
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
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
<?php
#adjust if needed
require_once ('../configuration.php');
$config=new JConfig;
$db_host= $config->host;
$db_host= $config->host;
$db_user= $config->user;
$db_password=$config->password;
$db_database=$config->db;
$fromname=$config->fromname;
$mailsite=$config->mailfrom;
$mailfrom="$fromname <$mailsite>";
$db_table= $config->dbprefix .'dataitems';
$db_feeds= $config->dbprefix .'datafeeds';
if (!($_resource = mysql_connect( $db_host, $db_user, $db_password, true ))) {
$_errorNum = 2;
$_errorMsg = 'Could not connect to MySQL';
print $_errorMsg;
exit;
}
mysql_select_db( $db_database, $_resource );
# adjust if you use
#your definition in xhelpers.php should look like:
#define ('DF_IMAGE','concat("http://img.example.com/cache/",`feed_id`,"/",`items_id`,".jpg")');
if ( preg_match("#.*/([0-9]+)/([0-9]+).jpg#",$_SERVER['REQUEST_URI'],$m) ) {
$dir='img/'.$m[1];
if ( ! is_dir($dir) ) { mkdir ($dir,0755,true); }
$img=$dir.'/'.$m[2].'.jpg';
$id=(int)$m[2];
$feed_q="select image from $db_table where items_id = $id limit 1";
$_feeds=mysql_query($feed_q,$_resource);
$p=mysql_result($_feeds,0);
if ( $p ) {
createthumb($p,"$img",100,100);
exit;
}
}
function createthumb($name,$filename,$new_w,$new_h)
{
$src_img=false;
$name=str_replace(array('[',']',' ','&'),array('%5B','%5D','%20','&'),$name);
$src_img=imagecreatefromstring(file_get_contents($name));
if ( ! $src_img ) {
if (preg_match("/(jpg|jpeg)$/i",$name)){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match("/gif$/i",$name)){
$src_img=imagecreatefromgif($name);
}
if (preg_match("/png$/i",$name)){
$src_img=imagecreatefrompng($name);
}
}
if ( ! $src_img ) {
return;
#or use local image as base
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$d_h=$thumb_h > 100?100:$thumb_h;
$dst_img=ImageCreateTrueColor($thumb_w,$d_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
imagejpeg($dst_img,$filename);
header("Content-type: image/jpg");
imagejpeg($dst_img);
imagedestroy($dst_img);
imagedestroy($src_img);
}
[/code]
In de template haal ik het alsvolgt op:
[code]<td style="145px; vertical-align:top; margin:10px 0px; padding:10px; overflow:hidden;" align="left"><a class="dflink" style="color:#00B4E8;" href="'.$product_ref.'" onClick="javascript:urchinTracker('.$item['feed'].');" target="_blank" rel="nofollow"><img style="max-width:100px;max-height:100px;" src="[b]http://m.domein.nl/'.$item['feed_id'].'/'.$item['items_id'].'.jpg[/b]" alt="'.$alt.'"/></a></td>';
[/code]
#adjust if needed
require_once ('../configuration.php');
$config=new JConfig;
$db_host= $config->host;
$db_host= $config->host;
$db_user= $config->user;
$db_password=$config->password;
$db_database=$config->db;
$fromname=$config->fromname;
$mailsite=$config->mailfrom;
$mailfrom="$fromname <$mailsite>";
$db_table= $config->dbprefix .'dataitems';
$db_feeds= $config->dbprefix .'datafeeds';
if (!($_resource = mysql_connect( $db_host, $db_user, $db_password, true ))) {
$_errorNum = 2;
$_errorMsg = 'Could not connect to MySQL';
print $_errorMsg;
exit;
}
mysql_select_db( $db_database, $_resource );
# adjust if you use
#your definition in xhelpers.php should look like:
#define ('DF_IMAGE','concat("http://img.example.com/cache/",`feed_id`,"/",`items_id`,".jpg")');
if ( preg_match("#.*/([0-9]+)/([0-9]+).jpg#",$_SERVER['REQUEST_URI'],$m) ) {
$dir='img/'.$m[1];
if ( ! is_dir($dir) ) { mkdir ($dir,0755,true); }
$img=$dir.'/'.$m[2].'.jpg';
$id=(int)$m[2];
$feed_q="select image from $db_table where items_id = $id limit 1";
$_feeds=mysql_query($feed_q,$_resource);
$p=mysql_result($_feeds,0);
if ( $p ) {
createthumb($p,"$img",100,100);
exit;
}
}
function createthumb($name,$filename,$new_w,$new_h)
{
$src_img=false;
$name=str_replace(array('[',']',' ','&'),array('%5B','%5D','%20','&'),$name);
$src_img=imagecreatefromstring(file_get_contents($name));
if ( ! $src_img ) {
if (preg_match("/(jpg|jpeg)$/i",$name)){
$src_img=imagecreatefromjpeg($name);
}
if (preg_match("/gif$/i",$name)){
$src_img=imagecreatefromgif($name);
}
if (preg_match("/png$/i",$name)){
$src_img=imagecreatefrompng($name);
}
}
if ( ! $src_img ) {
return;
#or use local image as base
}
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
if ($old_x > $old_y)
{
$thumb_w=$new_w;
$thumb_h=$old_y*($new_h/$old_x);
}
if ($old_x < $old_y)
{
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y)
{
$thumb_w=$new_w;
$thumb_h=$new_h;
}
$d_h=$thumb_h > 100?100:$thumb_h;
$dst_img=ImageCreateTrueColor($thumb_w,$d_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
imagejpeg($dst_img,$filename);
header("Content-type: image/jpg");
imagejpeg($dst_img);
imagedestroy($dst_img);
imagedestroy($src_img);
}
[/code]
In de template haal ik het alsvolgt op:
[code]<td style="145px; vertical-align:top; margin:10px 0px; padding:10px; overflow:hidden;" align="left"><a class="dflink" style="color:#00B4E8;" href="'.$product_ref.'" onClick="javascript:urchinTracker('.$item['feed'].');" target="_blank" rel="nofollow"><img style="max-width:100px;max-height:100px;" src="[b]http://m.domein.nl/'.$item['feed_id'].'/'.$item['items_id'].'.jpg[/b]" alt="'.$alt.'"/></a></td>';
[/code]