Posting or Uploading Files using cURL with PHP

cURL - groks those URLs

groks URLs

cURL is very important tool for PHP programmers, we tends to do so many thing with using this tool. Posting data, imitating a form post and lot more, it's usage is countless. Some time back I came across situation where we have to post files to a 3rd party faxing service. I knew there are many possibilities but I didn't wanted to get into sockets and file stream to get this done, just wanted to post FILE in addition to rest of the post data.

// URL on which we have to post data
$url = "http://localhost/tutorials/post_action.php";
// Any other field you might want to catch
$post_data['name'] = "khan";
// File you want to upload/post
$post_data['file'] = "@c:/logs.log";
 
// Initialize cURL
$ch = curl_init();
// Set URL on which you want to post the Form and/or data
curl_setopt($ch, CURLOPT_URL, $url);
// Data+Files to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
// Pass TRUE or 1 if you want to wait for and catch the response against the request made
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// For Debug mode; shows up any error encountered during the operation
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Execute the request
$response = curl_exec($ch);
 
// Just for debug: to see response
echo $response;

Above Code is the bare minimum required to post/upload file using CURL. As used in above example, it's not mandatory to use array index as "file". You can use anything required depending upon the requirement.

Posting multiple files is also easy, with the same code you can add multiple file upload using following lines:

$post_data['alian_error_log'] = "@c:/alian_app_error.log";
$post_data['myapp_error_log'] = "@c:/myapp_error.log";

Here @ is the key character, prefixing local file path with @ does all the trick.

 Read the rest of this entry »

Tags: , , , , , ,

Alternate to FIND_IN_SET for non-MySQL databases

Missing MySQL

Missing MySQL

If you are MySQL user initially at the beginning of your career and later on as the career progresses got in touch with other RDBMS then you might miss MySQL's FIND_IN_SET function badly. :)

What MySQL's FIND_IN_SET does is it returns position of the matched element in the SET. That SET of items must be comma-separated.

For example take following code into consideration:

SELECT FIND_IN_SET('b','a,b,c,d');

It will return "2" as the result. So generally what we have been doing is we use it not to find whether particular element is at what position in the comma-separated list but just to find simply that whether item exists in the list at all or not?

For that we use SQL something like following:

SELECT COUNT(0) FROM products WHERE FIND_IN_SET('7', category_id);

Above query will give you count of records which are having category_id 7 along with or without other categories. In table records might have values comma-separated like '4,5,7' or '7' or '2,7,8' or anything. So above expression in WHERE will return value greater than "zero" (0) and that row will be returned in result or calculated in count. Here category_id in products table is of type varchar.

Now when we are not using MySQL many times we can get similar result if we are not worried about the position of the item in the set but just want to make sure that it exists or not. It can be achieved with following SQL statement. Read the rest of this entry »

Tags: ,

Why IPv4 running out of space? What’s IPv6 and why do we care?

IPv4 is finally out of space.!

A typical IPv4 address looks like or . Where it can not grow after 255.255.255.255 (subnet mask). IPv4 uses 32-bit (four-byte) addresses, which limits the address space to 4,294,967,296 (232) possible unique addresses. However, some are reserved for special purposes such as private networks (~18 million addresses) or multicast addresses (~270 million addresses). This reduces the number of addresses that can potentially be allocated for routing on the public Internet. Read more about IPv4 and IPv4 space exhaustion on WiKiPedia.

Now IPv6 (Internet Protocol version-6) is the one who's going to save us from this space outage and will be the successor of IPv4. Windows, *nix and other software have support for IPv6 since quite long time now. Typical IPv6 address looks like 2002:7c7d:f78d::7c7d:f78d.

Here I am sharing this wonderful info-graphic prepared and published by FOCUS Research.

What is IPv6? And Why Should We Care

What is IPv6? And Why Should We Care

Like us and share with your friends if you like this post.!

Tags: , , ,

Penango – secure encrypted email w/ attachments for Gmail, Google Apps and Zimbra

Penango - secure emails

Penango - secure emails

Penango is a successor to free Firefox extension Gmail S/MIME, which let's you send encrypted emails using Gmail, Google Apps mail and Zimbra. As Google Apps or Gmail is not HIPAA complaint though it is running over Secure HTTP (HTTPS) protocol.

It comes as a Firefox, Maxthon and Internet Explorer extension.

Unlike Gmail S/MIME extension for Firefox, Penango is not going to be free but if you want to send signed emails (using email certificate) which are encrypted then I don't see any other alternates for Gmail or Google apps users.

See Penango's seamless integration with Gmail service, you can easily setup this for your Google apps email account too.

Penango's seamless integration with Gmail

Penango's seamless integration with Gmail

What all you need is download Penango extension for your browser and get free email certificate. That's it you'r ready to go. So far I am not sure about the licensing or pricing policies as Penango has not been publicly available so far.

Here I am providing you download information I have received while signing up for trial, you can either go and sign-up yourself or download Penango extension for your browser.

Download Penango from following location for your browser:

Read the rest of this entry »

Tags: , , , , ,

How to auto-restart Windows Service upon failure

Windows-service recovery from failure

Windows-service recovery from failure

If you're one of those who is administering Windows as a web-server administrator or as a windows admin and you need to take some action upon failure of your windows-service then right click on service for which you want to set recovery go to "Properties > Recovery" and choose action for First, Second and Subsequent failures of the service.

Here we have following choices:

Take No Action: Generally the default action unless modified for any non-windows service we or other programs might have created. For crucial services like web-server (apache or IIS), we usually would like to take some actions instead of doing nothing.

Restart the Service: The best option for 90% of the services which don't required restart of computer and you still want that windows-service to get started again, then choose this option.

Run a Program: I believe this option can either help you draw user's attention (as service runs in the background) by popping-up some alert message or to either writing some logs and then manually restarting that service via that program or there can be any other possibility which I don't know. Read the rest of this entry »

Tags: , , ,

Best Free Website Uptime Monitor

I came across a post on Mashable about an article on 10 Free Website Uptime Monitoring services, out of that I have analyzed and found 2 of them the best free solution out of all. One is UptimeRobot and another one is pingdom. Whether you have single website or multiple, if you want to check and monitor uptime of your website to verify the reliability of your web-server or hosting company then you should deploy up-time-monitoring service for your website/web-application. If you are running critical application than one should consider buying or using one for monitoring them.

Let me give you some idea about both the services:

UptimeRobot

UptimeRobot

UptimeRobot is completely free service for monitoring websites.

# of websites you can monitor per account: 50
Check Interval: 5 minute
Alert by: email, sms, rss, twitter

UptimeRobot looks at your site header’s status codes every five minutes and if the code comes back with a problem, does further checks. Then, if there are still issues, it lets you know about it pronto. According to about-us, they will try to keep this service free as long as possible.

pingdom

pingdom

pingdom is commercial monitoring service but it has a free sign-up with limited # of monitor. Basic free account let's you monitor 1 website. It comes with free iPhone application and monthly summary report as email.

# of websites you can monitor per account: 1
Check Interval: 1 minute
Alert by: E-mail, SMS (up to 20 per month), push alerts via iPhone app

I like that it allows you to select the time interval between 2 checks and the big deal is that at minimum you can select interval to 1-minute. The configuration is great and you can configure URL by HTTP/S or custom HTTP/S where you can set the PAYLOAD. We can choose between HTTP, TCP Port/Ping/DNS/UDP, SMTP/IMAP/POP3. See URL configuration screen below: Read the rest of this entry »

Tags: , , ,

Speed up PC startup with Soluto – Anti-Frustration Software

Soluto: Anti-Frustration Software

Soluto: Anti-Frustration Software

If you're one of those frustrated with sluggish PC startup then you should consider trying Soluto Beta. Soluto is an Anti-Frustration Software, which will help you easily view and remove unwanted items from the system startup and see what action other users in the community have taken for particular startup item.

With Soluto, we will have choose to Pause or Delay startup items, Pause will remove item from the startup still keeping in the registry, so that in future if you want you can queue them up and Delay will delay the startup item so that those services/processes will be little later after your startup which gives you quick access to the usable desktop/windows machine.

Basically their user interface is great as it shows you items in graphical way with amount of time you're saving by removing the startup items. Read the rest of this entry »

Tags: , , ,

Paying the bills.!