Hello i have a problem with my website. It is running slow. I asked the my server provider why is that, and they replied its because the webiste uses many embedded urls like youtube, vimeo, dailymotion and so on. And so i have to cache these embedded urls. I tried to use php_fast_cache (http://www.phpfastcache.com/). This is what i put on the page that returns the urls

  1. The urls are stored in the database like this https://www.youtube.com/watch?v=6__s2-iytA0
  2. $orimessage is a variable i use for the url https://www.youtube.com/watch?v=6__s2-iytA0
  3. On my server this folder cache.storage appeared so that means that goes on the include("phpfastcache/phpfastcache.php");

    include("phpfastcache/phpfastcache.php");
    $cache = phpFastCache("memcached");
    
    // try to get from Cache first.
    $results = $cache->get($orimessage);
    
    // Write to Cache Save API Calls next time
    $cache->set($orimessage, $results, 3600*24);
    foreach($results as $video) 
    {
    if(textlink($video))
        {
        //some code here
        }
    }
    

    i have these questions

    1. What i am doing wrong?
    2. Do i need to put *include("phpfastcache/phpfastcache.php");
      $cache = phpFastCache("memcached"); * on my config file?

What is the URL to your page? The ISP's notes sound more related to a frontend (i.e. your browser can't load that many videos at once) than something you could solve in PHP, but it would be impossible for us to know without looking at the page as it loads.

www.rovespier.com

Yeah, as I suspected this isn't to do with your PHP code at all. Your PHP file replies in about 200 milliseconds, then the browser spends all it's time downloading the many assets needed to render the page.

You would need to take an alternative approach to the front-end of this page in order to improve it's performance. There are two things that I would suggest trying first:

# 1. One big problem is this JPG file, amongst others on the page: http://www.rovespier.com/user_profile_uploads/141979704492.jpg

This file is 1.1MB, which is massive for a web page. You never want to allow users to upload files of an unlimited size without resizing them. If you resized this file on upload to make it the size that you want it at (looks like it is used at a resolution of 102x102 pixels) the results would load much faster.

# 2. For the YouTube videos I suggest embedding a thumbnail for the video as a link, rather than the video itself. This will cause the page to load much faster as well.

You can generate thumbnails by loading these files, replacing [video-id] with the ID for the video:

http://img.youtube.com/vi/[video-id]/0.jpg
http://img.youtube.com/vi/[video-id]/1.jpg
http://img.youtube.com/vi/[video-id]/2.jpg
http://img.youtube.com/vi/[video-id]/3.jpg

More infor on thumbnails in the first answer to this question on SO.

OK i got the thumbnail part i dont know to write the code because the url is stored in the database and i have to extract only the id of the url to do what you are saying but i ll do it. But how can i tell a user -i already set restrictions for uploading profile photos size, format and so on- not to upload something? Why not use cache to store these profile pictures. I thought cache was the answer to my problems.

Cache in the PHP level is not going to help in this case. The person at your hosting company was probably either talking about browser caching, or didn't really have a good answer to give you.

Allowing the users to upload the files is fine, but you need to resize them before you include them on a page. PHP has a bunch of built in functions in the GD and ImageMagick libraries that can do this. If you can't quite figure it out, I can write a function for you later tonight or torrow and show how I do it.

For the YouTube video ID you probably want to use explode() or preg_match() depending on how fancy you want to get.

commented: Thanks Isaac +2

I'll be very grateful if you help. The guy didnt say that it has to be in php just that the problem doesnt come from the their server. That i have to do some coding to general. Let me know if i have to send you some of my code.. Thanks in advance.

if(textlink($orimessage))
                                    {
                                    $link =textlink($orimessage);
                                    $em = new Wall_Expand($link);
                                    $site = $em->get_site();
                                    if($site != "")
                                        {
                                        $code = $em->get_iframe();
                                        if($code == "")
                                            {
                                            $code = $em->get_embed();
                                            if($code == "")
                                                {
                                                $codesrc=$em->get_thumb("large");
                                                }
                                            }
                                            if($codesrc)
                                            {
                                            echo '<div class="img_container"><img src='.$codesrc.' class="imgpreview" /></div>';
                                            }
                                            else if($code)
                                            echo $code;
                                        }
                                    } 
                                    $codesrc='';
                                    $code='';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.