PHP: Check broken links using curl
[code language=”php”] function check_url($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $data = curl_exec($ch); $headers = curl_getinfo($ch); curl_close($ch); return $headers[‘http_code’]; } $mainurl = "http://www.google.com"; $myurl = "http://www.google.com/gggg"; $mainsite = check_url($mainurl); $satus = check_url($myurl); if($mainsite == ‘200’){ if($satus == ‘200’){ echo "Its works"; }else{ echo "broken url"; } }else{ echo…
How to check MySQL and Apache uptime
Apache uptime: [code language=”php”] httpd fullstatus | grep uptime [/code] Server uptime: 4 hours 25 minutes 7 seconds MySQL uptime: [code language=”php”] mysqladmin version | grep Uptime [/code] Uptime: 1 hour 26 min 5 sec
Install Nginx Using Yum Command
Step #1: Install nginx repo Type the following wget command to install nginx yum configuration file: [code language=”php”] # cd /tmp [/code] CentOS Linux v6.x user type the following command: [code language=”php”] # wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm # rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm [/code] Step #2: Install nginx web-server Type the following yum command to install nginx web-server: [code…
jQuery: Post form with out reload the page using jquery.
[code language=”javascript”] $(".submit").click(function (){ var fname = $(this).val(); var dataString = ‘fname=’+ fname; $.ajax({ type: "POST", url: "addtodb.php", data: dataString, success: function(){ $(‘.successk’).fadeIn().show(); } }); return answer; }); [/code]
MySQL: Fixing MySQL crashed tables in SSH command line
[code language=”sql”] mysqlcheck –auto-repair –check -u username -p dbpassword [/code]
MySQL: Get the next Auto increment id of a table
[code language=”php”] $result = mysql_query("SHOW TABLE STATUS LIKE ‘".$table_name."’ "); $row = mysql_fetch_array($result); $next_id = $row[‘Auto_increment’]; [/code]
MySQL: Fetching distinct records from table HAVING COUNT greater than 3
[code language=”sql”] SELECT city, COUNT(id) AS id FROM YourTable GROUP BY city HAVING COUNT(id) > 3 [/code]
PHP: Regex remove everything after last slash & including last slash
Remove everything after last slash [code language=”php”] $string = ‘AAA/BBB/CCC’; echo preg_replace(‘#[^/]*$#’, ”, $string); [/code] Output: AAA/BBB/ Remove everything after last slash including last slash [code language=”php”] $string = ‘AAA/BBB/CCC’; echo preg_replace(‘#\/[^/]*$#’, ”, $string); [/code] Output: AAA/BBB
PHP: Regex for get everything before first forward slash
[code language=”php”] $str ="AAA/BBB/CCC"; $output = preg_replace(‘/(\/.*)/’, ”, $str); echo $output; [/code] Output: AAA