How to log php actions to html readable file?

I am making some kind of plugin for wordpress and lately i have a bit of problems, and im not sure if it’s plugin related or not.

The plugin is made to pull videos and their description, tags, thumb, etc…

Read More

So when i type in search term in my plugin and hit enter, the code goes to youtube search page,search video and pull data from it.

The problem is related to not pulling videos every time when i search. So sometime it works, sometime it doesn’t and it doesn’t matter if it’s same search terms or not.

Here’s an example of the code, it’s a bit long so ill just set search terms in variable instead in a form.

$searchterms = 'funny cat singing';

$get_search = rawurlencode($searchterms);
$searchterm = str_replace('+', ' ', $get_search);
$getfeed = curl_init();
curl_setopt($getfeed, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($getfeed, CURLOPT_URL, 'https://www.youtube.com/results?search_query='.$searchterm.'');
curl_setopt($getfeed, CURLOPT_RETURNTRANSFER, true);
curl_setopt($getfeed, CURLOPT_CONNECTTIMEOUT, 20);
$str = curl_exec($getfeed);
curl_close($getfeed);

$feedURL = str_get_html($str);

foreach($feedURL->find('ol[id="search-results"] li') as $video) {

get info like thumb time etc...

}

So sometime as i said i get the videos updated, and sometime i don’t

How can i record actions in log file so i can have or know what’s happening when i press search.

Something like

Pulling videos
Search terms: https://www.youtube.com/results?search_query=funny+cat+singing

And than if i get response from youtube something like

Page found, pulling videos.

Or if page is not found

Page not found, didn't get response from youtube.

If page is found than next step is to see if search term actually returns something, etc...

If i only know the basic how to start with logging, i will customize it later based on criteria what info i need to log.

Any advices?

Related posts

Leave a Reply

1 comment