Thursday, May 16, 2019
Tuesday, July 8, 2014
html 5 video tag.
<video width='320' height='240' controls autoplay>
<source src='http://someurl/video.mp4' type='video/mp4'>
<source src='http://someurl/video.ogg' type='video/ogg'>
<source src='http://someurl/video.webm' type='video/webm'>
<object data='movie.mp4' width='320' height='240'>
<embed width='320' height='240' src='movie.swf'>
</object>
</video>
Wednesday, November 20, 2013
Ajax Loader, $.getJSON Loader,
Just copy Paste on ur Script top,
It defines globally so no need add again and again for ajax events. It will fire for the jQuery Ajax events.
var cssOverlayOption = {
"position": "fixed",
"top": 0,
"left": 0,
"width": "100%",
"height": "100%",
"background-color": "#000",
"filter":"alpha(opacity=50)",
"-moz-opacity":"0.5",
"-khtml-opacity": "0.5",
"opacity": "0.5",
"z-index": 10000
};
var loaderImageCenter = {
"position":"relative",
"top":"50%",
"left":"50%"
};
var overlay = jQuery('<div id="overlay"><img src="images.jpg" id="loaderImage" width="99" height="102" title="Loading..." align="middle" /> </div>');
overlay.appendTo(document.body);
$(document).ajaxStart(function() {
$("#loaderImage").css(loaderImageCenter);
$("#overlay").css(cssOverlayOption).show();
});
It defines globally so no need add again and again for ajax events. It will fire for the jQuery Ajax events.
var cssOverlayOption = {
"position": "fixed",
"top": 0,
"left": 0,
"width": "100%",
"height": "100%",
"background-color": "#000",
"filter":"alpha(opacity=50)",
"-moz-opacity":"0.5",
"-khtml-opacity": "0.5",
"opacity": "0.5",
"z-index": 10000
};
var loaderImageCenter = {
"position":"relative",
"top":"50%",
"left":"50%"
};
var overlay = jQuery('<div id="overlay"><img src="images.jpg" id="loaderImage" width="99" height="102" title="Loading..." align="middle" /> </div>');
overlay.appendTo(document.body);
$(document).ajaxStart(function() {
$("#loaderImage").css(loaderImageCenter);
$("#overlay").css(cssOverlayOption).show();
});
Sunday, June 23, 2013
Detect Browser in php, User agent detection in php
function detect_mobile()
{
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
return true;
else
return false;
}
$mobile = detect_mobile();
if($mobile === true)
{
header("location:mobiledevice/index.php");
}
else
{
echo '<h3>you are looking via system browser</h3>';
/*echo $_SERVER['HTTP_USER_AGENT'];*/
}
{
if(preg_match('/(alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte)/i', $_SERVER['HTTP_USER_AGENT']))
return true;
else
return false;
}
$mobile = detect_mobile();
if($mobile === true)
{
header("location:mobiledevice/index.php");
}
else
{
echo '<h3>you are looking via system browser</h3>';
/*echo $_SERVER['HTTP_USER_AGENT'];*/
}
Detect Browser in Javascript, User agent detection in Javascript
<script type="text/javascript">
var ismobile = navigator.userAgent.match(/(alcatel) | (amoi) | (android) | (avantgo) | (blackberry) | (benq) | (cell) | (cricket) | (docomo) | (elaine) | (htc) | (iemobile) | (iPhone) | (ipad) | (ipaq) | (ipod) | (j2me) | (java) | (midp) | (mini) | (mmp) | (mobi) | (motorola) | (nec-) | (nokia) | (palm) | (panasonic) | (philips) | (phone) | (playbook) | (sagem) | (sharp) | (sie-) | (silk) | (smartphone) | (sony) | (symbian) | (t-mobile) | (telus) | (vodafone) | (wap) | (webos) | (wireless) | (xda) | (xoom) | (zte)/i);
if(ismobile)
{
// window.location = 'https://www.google.com.my';
alert("You are using mobile");
}
else
{
// window.location = 'https://www.yahoo.com';
alert("You are using system");
}
</script>
var ismobile = navigator.userAgent.match(/(alcatel) | (amoi) | (android) | (avantgo) | (blackberry) | (benq) | (cell) | (cricket) | (docomo) | (elaine) | (htc) | (iemobile) | (iPhone) | (ipad) | (ipaq) | (ipod) | (j2me) | (java) | (midp) | (mini) | (mmp) | (mobi) | (motorola) | (nec-) | (nokia) | (palm) | (panasonic) | (philips) | (phone) | (playbook) | (sagem) | (sharp) | (sie-) | (silk) | (smartphone) | (sony) | (symbian) | (t-mobile) | (telus) | (vodafone) | (wap) | (webos) | (wireless) | (xda) | (xoom) | (zte)/i);
if(ismobile)
{
// window.location = 'https://www.google.com.my';
alert("You are using mobile");
}
else
{
// window.location = 'https://www.yahoo.com';
alert("You are using system");
}
</script>
Tuesday, June 4, 2013
Href click submit jQuery, Simple JQuery validation, Form submit and reset jQuery. Self refresh jQuery
How to submit form with anchor tag/ href/a click in jquery?
Reload and Reset form jquery?
Simple validation in Jquery
// bind "click" event for links with title="submit"
$("a#submitcontact").click( function(){
// it submits the form it is contained within
$(this).parents("#register-form").submit();
});
$("#register-form").submit(function() {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
//$("#inline").empty().append('abc');
var address = $("input[name=Email]").val();
var emailError = true;
if($("input[name=Nama]").val() == ''){
$("#inline").empty().append('Please enter your Name.');
$('#Nama').focus();
return false;
}
else if($("textarea[name=Alamat]").val() == ''){
$("#inline").empty().append(' Please enter your Alamat');
$('#Alamat').focus();
return false;
}
else if($("input[name=Email]").val() == ''){
$("#inline").empty().append(' Please enter your E-mail address');
$('#Email').focus();
return false;
}
else if(!reg.test(address)) {
//emailError = true;
$("#inline").empty().append('Please enter your valid E-mail address.');
$('#Email').focus();
return false;
}
else if($("input[name=NoTelp]").val() == ''){
$("#inline").empty().append('Please enter your NoTelp.');
$('#NoTelp').focus();
return false;
}
else if($("textarea[name=Pesan]").val() == ''){
$("#inline").empty().append(' Please enter your Pesan');
$('#Pesan').focus();
return false;
}
else{
return true;
}
});
$("a#reseter").click( function(){
// it submits the form it is contained within
//opener.location.reload(true);
window.location.href = "contact.html";
// $(this).closest('form').find("input[type=text], textarea").val("");
// $(this).parents("#register-form").reset();
});
});
Wednesday, May 29, 2013
Location based Auto currency Updater in PHP, Currency and Update with two different sites..
$exectime = microtime();
$exectime = explode(" ",$exectime);
$exectime = $exectime[1] + $exectime[0];
$starttime = $exectime;
function get_geo_ip_code_wtanka($ipaddr)
{
set_time_limit(3); /// time in second 3 sec if it will take more then means next function will be load..
$userip = file_get_contents("http://geoip.wtanaka.com/cc/".$_SERVER['REMOTE_ADDR']);
$userip = strtolower($userip);
return $userip;
}
//echo $userip;
function get_geo_ip_code_sourceforge($ipaddr)
{
$userip = file_get_contents("http://ip2country.sourceforge.net/ip2c.php?format=JSON&ip=$ipaddr");
$userip = str_replace('"','',$userip);
$userip = '"'.$userip.'"'; /* it will returns u the JSON formate however u want u can change*/
$otup = json_decode($userip);
$otup = str_replace('{','',$otup);
$otup = str_replace('}','',$otup);
$otup = explode(',',$otup);
$len = count($otup);
$new = array();
for($i=1;$i<$len;$i++)
{
$rite = explode(':',$otup[$i]);
$new[] = array($rite[0]=>$rite[1]);
}
$value = strtolower($new[1]['country_code']);
$value = $value;
return $value;
}
$userip = get_geo_ip_code_wtanka($_SERVER['REMOTE_ADDR']) ;
$exectime = microtime();
$exectime = explode(" ",$exectime);
$exectime = $exectime[1] + $exectime[0];
$endtime = $exectime;
$totaltime = ($endtime - $starttime);
$ipaddr =$_SERVER['REMOTE_ADDR'];
if($totaltime>=3 || !file_exists("http://geoip.wtanaka.com/cc/$ipaddr") )
$userip = get_geo_ip_code_sourceforge($_SERVER['REMOTE_ADDR']);
Tuesday, January 8, 2013
Php - RSS feed into website
<?php
$feed = file_get_contents('http://samplesite.com/index.rss');
$rss = new SimpleXmlElement($feed);
foreach($rss->channel->item as $values) {
//var_dump($value);
//print_r($value);
//echo "<a href='$value->link' title='$value->title' target='_blank' >" . $value->title . "</a>";
}
?>
TIPS :
un-cmd var dump and view source .... u will getta good idea to split how u want....
un-cmd the print_r u will geta correct key values of the feed.....
Hope it will be useful this
Wednesday, October 10, 2012
Opencart issue . user multiple address not able to delete - bug fixed
Opencart version 1.5.3 and above...
we need to edit the code in catalog/controlles/account/address
find this line " $this->model_account_address->getTotalAddresses()"
existing code :
if ($this->model_account_address->getTotalAddresses()) {
$this->error['warning'] = $this->language->get('error_delete');
}
New Code :
(replace the above "existing code" to "New code" )
if ($this->model_account_address->getTotalAddresses() < 1) {
$this->error['warning'] = $this->language->get('error_delete');
}
Thanks to :
http://code.google.com/p/opencart/issues/detail?can=2&start=0&num=100&q=&colspec=ID Type Status Priority Milestone Owner Summary Reporter&groupby=&sort=&id=995
Magento CMS ADMIN Panel
In Admin-> CMS Module we have four Sub modules
- Pages { Its used to create the new pages. }
- Static blocks { Its used to create the new static block (like advertisement blocks etc) we can use this block where we wanted. }
- Widgets { Its used to improve the appearance of the store and communicate to other applications (like social network sites) }
- Polls { Its used to know the consumer or online users satisfaction ,and used to find and avoid the lack of Business. }
Pages
How to create the page?
Admin- > CMS -> Pages -> Add new page(Button)
- Page information *
we can set page which store we wanted .
- Content
- Design
we have four type of layout styles . 1 column ,2 columns with left bar ,2 columns with right bar ,3 columns.
our design will set the page style.
- Mata data
Content and Key words used to increase the traffic of our page and site.
After these we have to save the page.
If you want add the page link means you can use
<a href="{{store direct_url="new_home"}}">New Home</a>
call the above anchor tag in where you want. here " new_home" is the URL Key and "New Home" which is the Page title.
Static blocks
How to create the Static blocks?
Admin- > CMS -> Static blocks-> Add new Block(Button)
Block Title *
Identifier *
Store View *
Status *
Content *
we have to fill the above all .
If u wanted to add the block to ur page means you can use following code
{{block type="cms/block" block_id="ehp" }}
here ehp is a Identifier what you gave.
call above code to your page or which page you wanted.
Widgets
Admin- > CMS -> Pages -> Widgets ->Add New Widget Instance(Button) .
- Settings we can use the existing Widgets.
How to create Widgets by coding level through the MVC approach ?
Reference Url
http://www.magentocommerce.com/knowledge-base/entry/tutorial-creating-a-magento-widget-part-1 .
if you want to call the widget in your block or page go content -> WYSIWYG editor -> Insert widget option (2nd one from left top on editor)
Polls
Admin- > CMS -> Pages -> Polls ->Add New Poll (Button) .
Poll information and poll question and answer is needed . we have to fill above all.
and we have to "open" the polling option if we want.
Note : If we open(Active) two or three polling options means . that will show the front end one by one.
Multiple Pop in same page-Jquery .
u can use the following code you can easly add the same type of popups in samp page with diff "div"
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script> <style type="text/css">
.web_dialog_overlayback
{
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
height: 100%;
width: 100%;
margin: 0;
padding: 0;
background: #000000;
opacity: .15;
filter: alpha(opacity=15);
-moz-opacity: .15;
z-index: 101;
display: none;
}
.web_dialog
{
display: none;
position: fixed;
width: 380px;
height: 200px;
top: 50%;
left: 50%;
margin-left: -190px;
margin-top: -100px;
background-color: #ffffff;
border: 2px solid #336699;
padding: 0px;
z-index: 102;
font-family: Verdana;
font-size: 10pt;
}
.web_dialog_title
{
border-bottom: solid 2px #336699;
background-color: #336699;
padding: 4px;
color: White;
font-weight:bold;
}
.web_dialog_title a
{
color: White;
text-decoration: none;
}
.align_right
{
text-align: right;
}
</style>
<script type="text/javascript">
$(function (){
$("#btnShowSimple").click(function ()
{$("#overlay").show(); $("#dialog").fadeIn(300);
if (modal){$("#overlay").unbind("click"); }
else {$("#overlay").click(function (){$("#overlay").hide();$("#dialog").fadeOut(300);});}});
$("#btnClose").click(function (){$("#overlay").hide();$("#dialog").fadeOut(300);});});
$(function (){ $("#Simple").click(function ()
{$("#overlay1").show(); $("#dialog1").fadeIn(300);
if (modal){$("#overlay1").unbind("click"); }
else{$("#overlay1").click(function (){$("#overlay1").hide();$("#dialog1").fadeOut(300);});}});
$("#btnClose1").click(function (){$("#overlay1").hide();$("#dialog1").fadeOut(300);});});
</script>
</head>
<body>
<h3>JQuery Multiple Popup Dialogs in same page </h3>
<a id="btnShowSimple" value="Simple Dialog" /> cickhere</a>
<br />
<br />
<div id="overlay" class="web_dialog_overlayback"></div>
<div id="dialog" class="web_dialog">
<a href="#" id="btnClose">Close</a>
content one <!--you can add anything inside of this div-->
</div>
<br />
<br />
<a id="Simple" value="Simple Dialog" /> donglee</a>
<div id="overlay1" class="web_dialog_overlay"></div>
<div id="dialog1" class="web_dialog">
<a href="#" id="btnClose1">X</a>
content two <!--you can add anything inside of this div-->
</div>
</body>
</html>
Friday, December 16, 2011
phtml configuration in dreamweaver
C:\Program Files\Macromedia\Dreamweaver 8\Configuration\Extensions.txt
find "PHP,PHP3,PHP4...."
then we have to add phtml Extensions.txt
PHP,PHP3,PHP4,PHP5,TPL,PHTML:PHP Files
then add to the following file:MMDocumentTypes.xml
C:\Program Files\Macromedia\Dreamweaver 8\Configuration\DocumentTypes\MMDocumentTypes.xml
<documenttype id="PHP_MySQL" servermodel="PHP MySQL" internaltype="Dynamic" winfileextension="php,php3,php4,php5,phtml" macfileextension="php,php3,php4,php5,phtml" file="Default.php" writebyteordermark="false">
Friday, December 9, 2011
page count in java script and hide the block
<script type="text/javascript" language="javascript">
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function SetCookie (name, value)
{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain)) +((secure == true) ? "; secure" : "");
}
function DeleteCookie (name)
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
var expDays = 1;
var exp = new Date();
exp.setTime(exp.getTime() + (expDays*3600*24*15));
function amt()
{
var count = GetCookie('count')
if(count == null)
{
SetCookie('count','1')
return 1
}
else
{
var newcount = parseInt(count) + 1;
DeleteCookie('count')
SetCookie('count',newcount,exp)
return count
}
}
function getCookieVal(offset)
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
// End -->
</script>
<!-- STEP TWO: <span class="IL_AD" id="IL_AD12">Copy this</span> code <span class="IL_AD" id="IL_AD2">into the</span> BODY of your HTML document -->
<body>
<script LANGUAGE="JavaScript">
<!-- Begin
var kr=amt();
if (kr<2)
{
document.write('<img src="krishna.jpg" width="584" height="354">');
}
else if(kr>15){
DeleteCookie('count');
}
else
{
document.write("times up");
document.write("You are here for <b>" + kr + " times.");
}
// End -->
</script>
Monday, November 21, 2011
Tuesday, August 30, 2011
Dissable charactor on text box by javascript ,only allowing numbers at the text box
Its is used to disabled the charactor key pressing on javascript.
java script function
<--------------------------
function isnumky(evt)
{
var char1 = (evt.which) ? evt.which : event.keycode
if (char1 > 31 && (char1 < 48 || char1 > 57))
return false;
return true;
}
---------------------------------------->
html form
<input name="textfield" type="text" onkeypress="return isnumky(evnt)" size="50" />
Sunday, August 21, 2011
date of birth to age calculate by using java script regular expresion
<script type="text/javascript">
function CalculateAge(birthday) {
var re=/^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)\d\d+$/;
if (birthday.value != '') {
if(re.test(birthday.value ))
{
birthdayDate = new Date(birthday.value);
dateNow = new Date();
{
birthdayDate = new Date(birthday.value);
dateNow = new Date();
var years = dateNow.getFullYear() - birthdayDate.getFullYear();
var months=dateNow.getMonth()-birthdayDate.getMonth();
var days=dateNow.getDate()-birthdayDate.getDate();
if (isNaN(years)) {
var months=dateNow.getMonth()-birthdayDate.getMonth();
var days=dateNow.getDate()-birthdayDate.getDate();
if (isNaN(years)) {
document.getElementById('lblAge').innerHTML = '';
document.getElementById('lblError').innerHTML = 'Input date is incorrect!';
return false;
document.getElementById('lblError').innerHTML = 'Input date is incorrect!';
return false;
}
else {
document.getElementById('lblError').innerHTML = '';
document.getElementById('lblAge').innerHTML = years +' Years ' +months +' months '+days +' days';
document.getElementById('lblError').innerHTML = '';
document.getElementById('lblAge').innerHTML = years +' Years ' +months +' months '+days +' days';
}
}
else
{
document.getElementById('lblError').innerHTML = 'Date must be mm/dd/yyyy format';
return false;
}
}
}
</script>
</head>
<body>
<form id="form1" method="post">
<div>
Date of Birth :<input id="txtAge" onBlur="CalculateAge(this)" />(mm/dd/yyyy)
<span style="color: Red">
<Label ID="lblError" ></Label></span>
<br />
Age : <span id="lblAge"></span>
</div>
</form>
}
else
{
document.getElementById('lblError').innerHTML = 'Date must be mm/dd/yyyy format';
return false;
}
}
}
</script>
</head>
<body>
<form id="form1" method="post">
<div>
Date of Birth :<input id="txtAge" onBlur="CalculateAge(this)" />(mm/dd/yyyy)
<span style="color: Red">
<Label ID="lblError" ></Label></span>
<br />
Age : <span id="lblAge"></span>
</div>
</form>
Wednesday, August 10, 2011
water mark in php ..... restrict image file upload
water mark creation with image upload
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],"userimage/".$_FILES["fileToUpload"]["name"]);
//WaterMarkImages("images/".$_FILES["fileToUpload"]["name"]);
if ((($_FILES["fileToUpload"]["type"] == "image/gif")
|| ($_FILES["fileToUpload"]["type"] == "image/jpeg")
|| ($_FILES["fileToUpload"]["type"] == "image/jpg")
|| ($_FILES["fileToUpload"]["type"] == "image/pjpeg")
|| ($_FILES["fileToUpload"]["type"] == "image/png"))
&& ($_FILES["fileToUpload"]["size"] < 200000))
{
function WaterMarkImages($location)
{
$wm=imagecreatefromgif("image4.gif");
$wm_height=imagesy($wm);
$wm_width=imagesx($wm);
$image=imagecreatetruecolor($wm_width,$wm_height);
$image=imagecreatefromjpeg($location);
$size=getimagesize($location);
$x_pos=$size[0]-$wm-width-90;
$y_pos=$size[1]-$wm-width-800;
imagecopymerge($image,$wm,$x_pos,$y_pos,0,0,$wm_width,$wm_height,100);
imagejpeg($image,$location);
imagedestroy($image);
imagedestroy($wm);
}
call_user_func('WaterMarkImages', "userimage/".$_FILES["fileToUpload"]["name"]);
}
if ((($_FILES["fileToUpload1"]["type"] == "image/gif")
|| ($_FILES["fileToUpload1"]["type"] == "image/jpeg")
|| ($_FILES["fileToUpload1"]["type"] == "image/jpg")
|| ($_FILES["fileToUpload1"]["type"] == "image/pjpeg")
|| ($_FILES["fileToUpload1"]["type"] == "image/png"))
&& ($_FILES["fileToUpload1"]["size"] < 200000))
{
move_uploaded_file($_FILES["fileToUpload1"]["tmp_name"],"jadhagamimage/".$_FILES["fileToUpload1"]["name"]);
//WaterMarkImages1("images1/".$_FILES["fileToUpload1"]["name"]);
function WaterMarkImages1($location)
{
$wm=imagecreatefromgif("image4.gif");
$wm_height=imagesy($wm);
$wm_width=imagesx($wm);
$image=imagecreatetruecolor($wm_width,$wm_height);
$image=imagecreatefromjpeg($location);
$size=getimagesize($location);
$x_pos=$size[0]-$wm-width-90;
$y_pos=$size[1]-$wm-width-800;
imagecopymerge($image,$wm,$x_pos,$y_pos,0,0,$wm_width,$wm_height,100);
imagejpeg($image,$location);
imagedestroy($image);
imagedestroy($wm);
}
call_user_func('WaterMarkImages1', "jadhagamimage/".$_FILES["fileToUpload1"]["name"]);
$sql=("insert into table(fields,image field,,) values ('fields','".$_FILES["fileToUpload"]["name"]."','".$_FILES["fileToUpload1"]["name"]."')");
$n=mysql_query($sql);
header("location:home.");
}
}
Monday, June 13, 2011
fetch multiple contents with time out using curl with php mutitreading
this prgm used to fetch the contents from other servers .... wil set the sleeping time and and will see the time taken and how to fetch ,,, by using curl with php mutitreading
<style type="text/css">
<!--
.style2 {color: #FF0000; font-style:oblique; font-size:24px;}
-->
</style>
<?php
function addHandle(&$curlHandle,$url)
{
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_HEADER, 0);
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_multi_add_handle($curlHandle,$cURL);
return $cURL;
}
//execute the handle until the flag passed to function is greater then 0
function ExecHandle(&$curlHandle)
{
$flag=null;
do {
curl_multi_exec($curlHandle,$flag);//fetch pages in parallel
} while ($flag > 0);
}
$list[1] = "http://www.google.co.in/";
$list[2] = "http://in.yahoo.com/?p=in";
$list[3] = "http://www.rediff.com/";
$list[4] = "http://www.bing.com/";
$curlHandle = curl_multi_init();
for ($i = 1;$i <= 4; $i++)
$curl[$i] = addHandle($curlHandle,$list[$i]);
ExecHandle($curlHandle);
for ($i = 1;$i <= 4; $i++)
{
// set the sleeping time on 2 seconds
usleep(2000000);
{
// get the content from other servers
$text[$i] = curl_multi_getcontent ($curl[$i]);
echo $text[$i];
}
echo "<span class='style2'>$i time out".date("h:i:s")."</span>";
}
for ($i = 1;$i <= 4; $i++)//remove the handles
curl_multi_remove_handle($curlHandle,$curl[$i]);
curl_multi_close($curlHandle);
?>
Subscribe to:
Posts (Atom)
