Skip to content

Instantly share code, notes, and snippets.

View imrealashu's full-sized avatar

Ashish Singh imrealashu

View GitHub Profile
@imrealashu
imrealashu / php speed up tips.html
Created March 30, 2018 19:06 — forked from bsalim/php speed up tips.html
63 Tips for speeding up PHP
<html>
<body>
<p>Here are Webber’s points:</p>
<ul>
<li>If a method can be static, declare it static. Speed improvement is by a factor of 4.</li>
<li>echo is faster than print.(<em>* compare with list from phplens by John Lim</em>)</li>
<li>Use echo’s multiple parameters instead of string concatenation.</li>
<li>Set the maxvalue for your for-loops before and not in the loop.</li>
<li>Unset your variables to free memory, especially large arrays.</li>
<li>Avoid magic like __get, __set, __autoload</li>
<?php
public function scopeClosestTo($query, $latitude, $longitude, $radius)
{
return $query
->whereRaw("
ST_DISTANCE_SPHERE(
POINT($latitude, $longitude),
POINT(lat, lng)) < $radius
");
}
@imrealashu
imrealashu / sql_sp_distance_sphere.sql
Last active December 27, 2017 16:31
Mysql raw query for spacial distance calculations.
SELECT *,
ST_DISTANCE_SPHERE(
POINT(`table_name`.`lat`, `table_name`.`lng`),
POINT('24.2449530', '85.4870880')) as `distance`
FROM `table_name