Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.
Smarty urlExists timeout

 
Post new topic   Reply to topic    Smarty Forum Index -> Documentation
View previous topic :: View next topic  
Author Message
michielh
Smarty n00b


Joined: 15 Aug 2009
Posts: 4

PostPosted: Sat Aug 15, 2009 3:54 pm    Post subject: Smarty urlExists timeout Reply with quote

Hi guys, sorry for doing this but I must have created two posts before I can post my real question. This is the first one.

Last edited by michielh on Sat Aug 15, 2009 3:56 pm; edited 1 time in total
Back to top
View user's profile Send private message
michielh
Smarty n00b


Joined: 15 Aug 2009
Posts: 4

PostPosted: Sat Aug 15, 2009 3:54 pm    Post subject: Reply with quote

And this is the second one. Really sorry.
Back to top
View user's profile Send private message
michielh
Smarty n00b


Joined: 15 Aug 2009
Posts: 4

PostPosted: Sat Aug 15, 2009 3:54 pm    Post subject: Reply with quote

Hi guys, I'm looking at a timeout error and although I've searched everywhere, I cannot find a way to fix it in Smarty. Here's my problem:

A foreach-loop implemented in a template to list personal details makes use of the following code to determine whether or not a picture of the member is available on the server:

Code:

{urlExists url="`$smarty.const.BASE_HREF`data/members/`$member.memberid`.jpg"}
{if $urlExists}
<img src="data/members/{$member.memberid}.jpg" alt="{$member.name}" title="{$member.name}" />
{else}
<img src="images/nophoto.jpg" alt="{$member.name}" title="{$member.name}" />
{/if}


With this code still active, a server timeout occurs after the 19th member cycle. The other 20 members aren't even being displayed on the page. But when I remove the code, the page is displayed within 2 seconds. Is there a better (and less resource consuming Wink ) way to attach the default 'nophoto.jpg' picture to members without one?

Thanks in advance for the help!


Michiel
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7265
Location: Lincoln Nebraska, USA

PostPosted: Sat Aug 15, 2009 3:58 pm    Post subject: Reply with quote

Testing if a URL exists is not a very good way to determine if they have a photo or not. I'd use a database entry or something. Testing if a URL exists requires network latency on each test, and will timeout if it cannot make a connection for any reason.
Back to top
View user's profile Send private message Visit poster's website
michielh
Smarty n00b


Joined: 15 Aug 2009
Posts: 4

PostPosted: Sat Aug 15, 2009 4:23 pm    Post subject: Reply with quote

Thanks for your swift reply, mohrt.

If I would have build the website from the ground up I would indeed have added a check (for instance a boolean value) to the userdetails table in order to see if the picture is in place. However, the previous developer has left and I cannot make changes to the database structure he has created. It would make things too difficult.

Thanks for the advice, I have deleted the ifExists code and replaced it with the following:

Code:

<img src="data/members/{$member.memberid}.jpg" width="150" height="200" style="background-image:url(images/nophoto.jpg);"/>


And even though Iexplore users see a small cross at the top left corner of the image, I think it's ok.

Thanks for helping me out, michiel
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Smarty Forum Index -> Documentation All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP