5 Ways to Make HTTP Requests in PHP
HTTP requests are a hallmark of modern, web-based applications—especially in PHP. We have to interact with all manner of APIs and external services, such as Google Cloud, Facebook, and AWS, on almost a daily basis. I’d go so far as to say that it might well be one of the first things that you learn after you’ve mastered PHP’s foundations. It was for me.
That said, like many modern software development languages, there’s more than one way to make HTTP requests. So in this post, I’m going to introduce you to five of the most common options for making them in PHP. I’ll show how to use them and cover some of their respective strengths and weaknesses. I won’t explore them in intimate detail, rather give a broad introduction to each one.
The approaches that I’ll cover are:
Build a Multilingual IVR With Twilio and PHP
Imagine your company's sales are growing rapidly and your sole customer support employee can no longer handle the increased call volume. In this instance, the only thing worse than an unsatisfied customer is an unsatisfied customer who finds your customer support number constantly busy.
So, you decide to do something about it and create an IVR (Interactive Voice Response). Nice, but your customers are from all around the world so not all of them can speak your language, and those that can may not, necessarily, be fluent. The solution? Create a multilingual IVR!
What is an IVR?
An IVR is a technology that allows humans to interact with a computer-operated phone system through the use of voice and DTMF (Dual-tone multi-frequency signaling) tones input via a keypad.
In other words, when a customer calls, a computer system will respond and redirect …
How to Create a Landing Page with Laravel, Vue.js, and SendGrid
Landing pages are everywhere in modern business.
They're used when people offer a free giveaway in return for someone joining a mailing list, to sell a product or service, and as glorified resumes.
Landing pages are a great solution for these kinds of business needs as they can be rapidly created and deployed. Knowing how to create them can also be a great skill for developers to have, whether creating landing pages for others or for personal projects.
In this tutorial, I'll show you how to create a landing page using a combination of Laravel 8, Vue.js, and SendGrid. It's a reasonably long tutorial. By the end of it, I'm confident that you'll have learned a lot.
To complete the tutorial, you will need the following 4 things in your local development environment:
How I’m Using Twilio and Laravel to Have a Eurovision Party in Lockdown
I've always been a fan of Eurovision. Every year one of our group hosts a Eurovision party that is themed around the host country's food and drink. The evening is spent marking each of the acts giving points for categories such as entertainment value, set, staging and props, and not forgetting any costume changes á la Bucks Fizz in 1981. We then tally them all up to come up with our overall winner and see if the jury agrees.
Here in the UK, due to the Coronavirus pandemic, 2021's Eurovision party isn't able to take place as we'd like, so I decided to take matters into my own hands and replicate the voting experience using Twilio and Laravel. Here's how I did it.
The Initial Idea
I decided to create an admin dashboard where I could add my friends as Voters. I wanted to “invite” them after they’d been …
Build a Simple Chat Room App in React with Laravel Breeze and Twilio's Conversations API
2020 was a huge year for Laravel. It was the year that we saw this beloved framework take leaps and bounds over its competition and push the PHP ecosystem further. The Laravel team managed to make the framework even more powerful by adding new authentication and scaffolding features, which include Jetstream and Breeze.
Many developers know that full-stack apps with a Vue frontend can be quickly spun up with Laravel Jetstream. What many don’t know is that recently, the Laravel team made it easy to make an Inertia app with Laravel Breeze.
With this knowledge, let’s have some fun and make a very simple Discord-like app called “Twilcord” that will let multiple users join a room via a phone number or username. Instead of the default Vue frontend, we’ll be using React. This article will show you that you don’t need to build separate backends and frontends …
Get Started Testing a Yii2 API Using Codeception
Testing (and TDD by extension) has drummed up more than its fair share in terms of significant debates. While proponents and opponents may disagree on specifics, they always come to one conclusion: it is unprofessional to ship untested code. Testing provides a level of assurance, not only that the code meets the provided specification but that it can handle edge cases that may be encountered upon deployment.
In this article, I will show you how to test a RESTful API built with the Yii framework (version 2)usingCodeception. Built on PHPUnit, Codeception provides support for creating and running unit, functional, and acceptance tests on PHP applications in a unified manner.
To allow us to focus on the key aspects of testing in this tutorial, we’ll be building on the result of a previous tutorial where Yii2 was used to build a secure RESTful API. You're, however, very free …
Build a RESTful API using PHP and Yii2
Since its introduction, RESTful architecture has redefined the way we think about (and build) software applications by breaking down complex application ecosystems into smaller, more focused applications communicating with each other via RESTful calls.
Client-Server Architecture allows web clients and mobile apps to communicate with the same infrastructure (such as a server-side API) to provide a seamless user experience.
In this tutorial, I will show you how to build a RESTful API using the Yii framework (version 2)- a high-performance, component-based PHP framework.
A basic understanding of the Yii framework and PHP will be of help in this tutorial. However, I will provide brief explanations and links to the applicable parts of the official documentation throughout the tutorial. If you’re unclear on any concept, you can review the linked material before continuing.
Additionally, you need to have the following installed on your system:
- PHP version 7 or higher with …
Implement Two-Factor Authentication With Symfony and Twilio's Authy App and API
The username and password are dead! Well, not really. But considering the times we live in, it’s dangerous to rely on them alone. Computers are getting faster and better at guessing our passwords. And there are numerous databases containing stolen passwords roaming the web. Consequently, you also need to use Two-factor Authentication (2FA) in order to keep your account safe.
- A basic working understanding of PHP and Symfony
- PHP 7.4
- A Twilio account
- The Authy app
- The Symfony CLI
Let's get started
To get started, create a new Symfony project, named
2-fa-demo, and switch to the newly created project’s directory using the commands below.
symfony new 2-fa-demo cd 2-fa-demo
Next, you need to install …
Create a Mailing List in PHP using Laravel, Vue.js, and Twilio's SendGrid Email API
The importance of email marketing cannot be over-emphasized in modern-day business, mostly because of its cost-effectiveness and conversion-to-sales ratio. This tutorial will teach you how to use Twilio’s SendGrid Email API with Laravel and a Vue.js frontend to send bulk emails to more than 100 email addresses at once. This removes the pain of sending out emails slowly, as well as the possibility of emails going to spam.
After we’re finished, you will have developed a custom mailing list that:
- Allows anyone to enter their email address and save it to the application database
- Send out bulk emails to provided email addresses
To follow along with this tutorial you should have the following in place:
How to Send 1000 (or more) Text Messages in PHP Without Timing Out
PHP developers of all experiences are painfully aware that your script may not execute if it takes longer than 30 seconds to process. There’s nothing worse than failing to do proper testing and finding that your code doesn’t scale in production.
In a previous tutorial, I shared how you can calculate the script execution time of sending SMS messages. At the conclusion we discovered that each message takes about .33 seconds to send, meaning that PHP’s 30 second timeout will allow you to send 90 messages before failure.
So what do you do when you want to send more than 90 messages? What about 1000?
Unfortunately, if you want to send bulk SMS (or WhatsApp) messages using the standard Programmable Messaging API, it’s not going to scale in PHP. Great engineering practices would suggest that you break apart your requests and run batches asynchronously. However, Twilio engineering has …