Archive

Posts Tagged ‘PHP’

PHP based torrent file creator, tracker and seed server – PHPTracker

September 16th, 2011 Comments off

Great software!

Why PHPTracker? Because it’s not “just a tracker”, it contains a seeder server too so the distribution of your files is automatic. This is a big step for the content providers to adapt this amazing technology and change the stereotype that “torrent = warez”.

PHP based torrent file creator, tracker and seed server – PHPTracker.

Categories: Linux, MySQL, PHP Tags: , , ,

ffmpeg-php – error: ‘PIX_FMT_RGBA32’ undeclared (first use in this function)

August 24th, 2011 Comments off

ffmpeg-php – error: ‘PIX_FMT_RGBA32’ undeclared (first use in this function) | HOW GEEK!.

/root/install/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function 'zim_ffmpeg_frame_toGDImage':
/root/install/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: 'PIX_FMT_RGBA32' undeclared (first use in this function)
/root/install/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: (Each undeclared identifier is reported only once
/root/install/ffmpeg-php-0.6.0/ffmpeg_frame.c:336: error: for each function it appears in.)
/root/install/ffmpeg-php-0.6.0/ffmpeg_frame.c: In function 'zim_ffmpeg_frame_ffmpeg_frame':
/root/install/ffmpeg-php-0.6.0/ffmpeg_frame.c:421: error: 'PIX_FMT_RGBA32' undeclared (first use in this function)
make: *** [ffmpeg_frame.lo] Error 1

To fix this, replace PIX_FMT_RGBA32 with PIX_FMT_RGB32 .

You can use “rpl” to replace files recursively:

cd to the ffmpeg-php folder and run this command (beware!):

rpl -R PIX_FMT_RGBA32 PIX_FMT_RGB32 *

If rpl not installed on your system, install it, for example:

yum install rpl
Categories: Linux, PHP Tags: , ,

Plesk: Premature end of script headers OR cgi_wrapper target uid/gid mismatch (500 Internal server error)

January 24th, 2011 1 comment

When you have a newly installed Plesk, it’s not enought to run PHP-scripts in CGI. Unfortunately.

You need manually copy suexec file from Plesk binaries file folder to system binaries folder.

In common cases it does command:

# cp /usr/local/psa/suexec/psa-suexec /usr/sbin/suexec

If cp cannot find any of files, search they manually

# locate suexec

Important! It’s recommended to make a copy of system’s suexec file

# cp /usr/sbin/suexec /usr/sbin/suexec_old
Categories: Linux, Plesk Tags: , , , ,

PHP get Google backlinks for domain/site

February 20th, 2010 Comments off

Function below allow you to get count of Google backlinks for requested page

function getGoogleOuterLinksCount($url) {
 $domain = preg_replace('/^www\./','',array_shift(split('/',$url)));

 /*  I strongly recommend you to use www.google.<you country zone> version of Google */
 $html = "http://www.google.com/search?q=link:".$domain."&hl=en"; 

 $content = getRemoteFile($html);
 if (preg_match('/<div id=resultStats>(\d+) results/i',$content,$arr)) {
   $t = $arr[1];
   $t = str_replace(' ','',$t);
   $t = str_replace(',','',$t);
   return (int)$t;
 } else
   return 0;
}

function getRemoteFile($url) {
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

   $data = curl_exec($ch);

   if(curl_errno($ch)) {
      echo "Error!  Error code:".curl_errno($ch)." Error:".curl_error($ch);
      curl_close($ch);
      return false;
   }

   list($header, $data) = preg_split("/\r?\n\r?\n/", $data, 2);

   return $data;
}
Categories: PHP Tags: ,

PHP get Google index for domain/site. Indexed by Google pages count

February 19th, 2010 1 comment

The function below allow you to get the count of pages indexed by Google.

function getGoogleIndexCount($url) {
   $html = "http://www.google.com/search?hl=en&safe=off&q=site%3A".$url."&btnG=Search"; // I strongly recommend you to use www.google.<you country zone> version of Google

   $content = getRemoteFile($html);
   if (preg_match('/<div id=resultStats>(\d+) results/i',$content,$arr)) {
       $t = $arr[1];
       $t = str_replace(' ','',$t);
       $t = str_replace(',','',$t);
       return (int)$t;
   } else return 0;
}

function getRemoteFile($url) {
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_HEADER, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

   $data = curl_exec($ch);

   if(curl_errno($ch)) {
      echo "Error!  Error code:".curl_errno($ch)." Error:".curl_error($ch);
      curl_close($ch);
      return false;
   }

   list($header, $data) = preg_split("/\r?\n\r?\n/", $data, 2);

   return $data;
}
Categories: PHP Tags: ,

Smarty parse a string as template

October 16th, 2009 Comments off

It’s the best way to parse a string as Smarty template. You need to follow only 3 steps!

First of all we need to register a new template resource – string.

$smarty->register_resource("string", array("string_get_template",
 "string_get_timestamp",
 "string_get_secure",
 "string_get_trusted"));

Then add function implementations

function string_get_template ($tpl_name, &$tpl_source, &$smarty_obj) {
    global $smartyStringTemplates;
    $tpl_source = $smartyStringTemplates[$tpl_name];
    return true;
}

function string_get_timestamp($tpl_name, &$tpl_timestamp, &$smarty_obj) {
    // do database call here to populate $tpl_timestamp.
    $tpl_timestamp = time;
    return true;
}

function string_get_secure($tpl_name, &$smarty_obj) {
    // assume all templates are secure
    return true;
}

function string_get_trusted($tpl_name, &$smarty_obj) {
    // not used for templates
}

And the last step. Create an array of string templates and parse a string by passing it’s index in array

$smartyStringTemplates = array('{php}date(){/php}', '{$helloWold}');

print $smarty->fetch("string:1"); // will fetch a string {$helloWold}
Categories: PHP Tags: ,