• png uz jpg ar izgriezšanas funkciju

    function png2jpg($originalFile, $outputFile, $quality, $crop, $crop2, $cirpt) {
    $image = imagecreatefrompng($originalFile);
    if ($crop>0){
    $size = getimagesize($originalFile);
    $width = $size[0];
    $height = $size[1];
    $ww=$crop;
    $hh=$crop2;
    if ($cirpt==1){
    if($width> $height) {
    $x=$width/$ww;
    } else {
    $x=$height/$hh;
    }
    $thumb_size1=ceil($width/$x);
    $thumb_size2=ceil($height/$x);
    } else if ($cirpt==2){
    $thumb_width = $crop;
    $thumb_height = $crop2;
    $width = $size[0];
    $height = $size[1];
    $original_aspect = $width / $height;
    $thumb_aspect = $thumb_width / $thumb_height;
    if ( $original_aspect >= $thumb_aspect )
    {
    // If image is wider than thumbnail (in aspect ratio sense)
    $new_height = $thumb_height;
    $new_width = $width / ($height / $thumb_height);
    }
    else
    {
    // If the thumbnail is wider than the image
    $new_width = $thumb_width;
    $new_height = $height / ($width / $thumb_width);
    }
    $thumb_size1=$crop;
    $thumb_size2=$crop2;
    $x1 = 0 - ($new_width - $thumb_width) / 2;
    $y1 = 0 - ($new_height - $thumb_height) / 8;
    $x=0;
    $y=0;
    } else {
    $new_width = $size[0];
    $new_height = $size[1];
    $width = $size[0];
    $height = $size[1];
    }
    $new_im = ImageCreatetruecolor(($thumb_size1),$thumb_size2);
    imagecopyresampled($new_im,$image,$x1,$y1,$x,$y,$new_width,$new_height,$width,$height);
    imagejpeg($new_im, $outputFile, $quality);
    imagedestroy($new_im);
    } else {
    imagejpeg($image, $outputFile, $quality);
    imagedestroy($image);
    }
    }


  • curl post pieprasījums

    curl_setopt($handle, CURLOPT_URL,"http://www.example.lv/kautkas.php");
    curl_setopt($handle, CURLOPT_POST, true);
    curl_setopt($handle, CURLOPT_POSTFIELDS, array("var1" => $var1 ));
    curl_exec($handle);


  • json no php masīva

    $json[]=array('artist'=>'var1','title'=>$var2));
    echo json_encode($json);


  • Youtube ID no dziesmas nosaukuma

    $homepage = file_get_contents('https://gdata.youtube.com/feeds/api/videos?q='.urlencode($dz_izpilditajs).'%20-%20'.urlencode($dz_nosaukums).'&orderby=relevance&start-index=1&max-results=1&v=2&alt=json');
    $ytraw=json_decode($homepage, true);
    $here = explode(":", $ytraw['feed']['entry'][0]['id']['$t']);
    $num = (count($here) - 1);
    $yt = $here[$num];

    Vairāk info šeit:
    https://developers.google.com/youtube/2.0/developers_guide_protocol_api_query_parameters?hl=cs


  • MySQL utf-8

    [client]
    default-character-set=utf8

    [mysql]
    default-character-set=utf8

    [mysqld]
    collation-server = utf8_unicode_ci
    init-connect='SET NAMES utf8'
    character-set-server = utf8


  • APACHE


    prefork

    mpm_prefork is.. well.. it’s compatible with everything. It spins of a number of child processes for serving requests, and the child processes only serve one request at a time. Because it’s got the server process sitting there, ready for action, and not needing to deal with thread marshaling, it’s actually fasterthan the more modern threaded MPMs when you’re only dealing with a single request at a time – but concurrent requests suffer, since they’re made to wait in line until a server process is free. Additionally, attempting to scale up in the count of prefork child processes, you’ll easily suck down some serious RAM.

    It’s probably not advisable to use prefork unless you need a module that’s not thread safe.

    Use if: You need modules that break when threads are used, like mod_php. Even then, consider using FastCGI and php-fpm.

    Don’t use if: Your modules won’t break in threading.

    worker

    mpm_worker uses threading – which is a big help for concurrency. Worker spins off some child processes, which in turn spin off child threads; similar to prefork, some spare threads are kept ready if possible, to service incoming connections. This approach is much kinder on RAM, since the thread count doesn’t have a direct bearing on memory use like the server count does in prefork. It also handles concurrency much more easily, since the connections just need to wait for a free thread (which is usually available) instead of a spare server in prefork.

    Use if: You’re on Apache 2.2, or 2.4 and you’re running primarily SSL.

    Don’t use if: You really can’t go wrong, unless you need prefork for compatibility.

    However, note that the treads are attached to connections and not requests – which means that a keep-alive connection always keeps ahold of a thread until it’s closed (which can be a long time, depending on your configuration). Which is why we have..

    event

    mpm_event is very similar to worker, structurally; it’s just been moved from ‘experimental’ to ‘stable’ status in Apache 2.4. The big difference is that it uses a dedicated thread to deal with the kept-alive connections, and hands requests down to child threads only when a request has actually been made (allowing those threads to free back up immediately after the request is completed). This is great for concurrency of clients that aren’t necessarily all active at a time, but make occasional requests, and when the clients might have a long keep-alive timeout.

    The exception here is with SSL connections; in that case, it behaves identically to worker (gluing a given connection to a given thread until the connection closes).

    Use if: You’re on Apache 2.4 and like threads, but you don’t like having threads waiting for idle connections. Everyone likes threads!

    Don’t use if: You’re not on Apache 2.4, or you need prefork for compatibility.


  • PHP Preg_match lai izvilktu pirmo youtube linku no teksta

    preg_match('#(?:http://)?(?:www\.)?(?:youtube\.com/(?:embed/|v/|watch\?v=)|youtu\.be/)([\w-]+)(?:\S+)?#', $string, $match);


  • Youtube thumbnail no video identifikatora

    $url="http://www.youtube.com/watch?v=mHifGmeToVU";
    parse_str(parse_url($url,PHP_URL_QUERY),$my_array);
    echo $my_array['v'];
    echo "<img alt="" src="http://img.youtube.com/vi/&quot;.$my_array[" />";

    VAI
    function youtube_id_from_url($url) {
    $pattern =
    '%^# Match any youtube URL
    (?:https?://)? # Optional scheme. Either http or https
    (?:www\.)? # Optional www subdomain
    (?: # Group host alternatives
    youtu\.be/ # Either youtu.be,
    | youtube\.com # or youtube.com
    (?: # Group path alternatives
    /embed/ # Either /embed/
    | /v/ # or /v/
    | /watch\?v= # or /watch\?v=
    ) # End path alternatives.
    ) # End host alternatives.
    ([\w-]{10,12}) # Allow 10-12 for 11 char youtube id.
    $%x'
    ;
    $result = preg_match($pattern, $url, $matches);
    if (false !== $result) {
    return $matches[1];
    }
    return false;
    }

    echo youtube_id_from_url(‘http://youtu.be/NLqAF9hrVbY’); # NLqAF9hrVbY

    http://img.youtube.com/vi//0.jpg
    http://img.youtube.com/vi//1.jpg
    http://img.youtube.com/vi//2.jpg
    http://img.youtube.com/vi//3.jpg

    http://img.youtube.com/vi//default.jpg

    http://img.youtube.com/vi//hqdefault.jpg

    http://img.youtube.com/vi//mqdefault.jpg

    http://img.youtube.com/vi//sddefault.jpg

    http://img.youtube.com/vi//maxresdefault.jpg


  • ApacheTOP

    apachetop -f /var/www/vhosts/howtogeek.com/statistics/logs/access_log


  • PHP instalētie moduļi

    php -m
    php -i