- How do I install instasent/sms-counter-php in a Laravel project?
- Install it with Composer using composer require instasent/sms-counter-php. Because it is a framework-agnostic PHP library, there is no service provider, facade, config file, or publishable asset to register in Laravel. You instantiate the counter class directly in your code, or preferably bind it behind your own interface in a service provider.
- Is instasent/sms-counter-php compatible with Laravel 10 and Laravel 11?
- The library is not tied to any Laravel version because it has no framework coupling, so it can be used inside Laravel 10, 11, or any other release running a compatible PHP version. The real compatibility question is PHP itself: there is no visible PHP 8.x support declaration, so test it on your target runtime before relying on it. Pin the version and run your test suite on the PHP version you deploy.
- How does the library decide between GSM-7 and Unicode encoding?
- It classifies the message body as GSM 03.38 7-bit or UCS-2 and counts characters and segments according to that classification. If the message contains any character outside the GSM-7 alphabet, the whole message typically flips to Unicode, which roughly halves capacity from 160/153 to 70/67 characters per segment. This matters because a single non-GSM character can change both the segment count and the cost.
- Does instasent/sms-counter-php handle multipart or concatenated SMS messages?
- Yes, the library computes single-part versus multipart segment counts using the standard thresholds of 160 and 153 characters for GSM-7 and 70 and 67 for UCS-2. The first segment has the larger capacity and subsequent segments are reduced to allow for the concatenation header. Validate its output against real messages, because edge cases in segment math are where incorrect counts appear.
- Can I use instasent/sms-counter-php outside of Laravel?
- Yes. It is a standalone PHP utility with no framework dependencies, so it works in plain PHP scripts, Symfony applications, CLI tools, and queue workers. That same stateless design makes it safe in long-running processes such as Laravel Octane or queued jobs, provided you avoid static caching around it.
- Is instasent/sms-counter-php actively maintained and does it support PHP 8?
- The last release was in June 2019 and the project has a small star count with a single maintainer, with no visible CI matrix or security response process. There is no clear evidence of PHP 8.x support, so deprecation warnings or behavioural drift on PHP 8.2 or later are plausible. Because it is MIT licensed, the safest approach is to pin the version, wrap it behind your own contract, and keep a fork option open.
- How should I validate SMS length before sending in a Laravel application?
- Call the counter at the boundary where messages are prepared, such as a form request rule, a notification channel, or a job before dispatch, and compare the returned segment count against your limit. Returning a value object with encoding, length, segments, and remaining characters lets you show a precise error message to users. Keep that validation authoritative in one place so different code paths cannot disagree about segment counts.
- How does the counter treat GSM-7 extension characters and emoji?
- GSM-7 extension characters such as curly braces, square brackets, the euro sign, caret, backslash, tilde, and pipe occupy two septets, so they affect segment math and not just raw character counts. Emoji and zero-width-joiner sequences are multiple UTF-16 code units under UCS-2, and carriers count code units rather than grapheme clusters. Verify the library handles both cases correctly with your own test fixtures before trusting it in production.
- Does instasent/sms-counter-php account for UDH overhead in concatenated messages?
- The standard per-segment limits of 153 GSM-7 characters and 67 UCS-2 characters already reflect the 6 to 7 byte user data header used for concatenation. The important check is whether the library applies those reduced limits to every segment after the first rather than only to the total. Confirm this with a message that just crosses the single-part boundary, since an off-by-one here directly causes unexpected splits or double billing.
- What alternatives exist to instasent/sms-counter-php for counting SMS segments?
- Alternatives include other standalone SMS length libraries, helpers bundled with SMS gateway SDKs, or a small in-house counter built from the public GSM 03.38 tables and 3GPP segment rules. For many teams the in-house route is attractive because the domain is bounded and auditable in an afternoon. Whichever option you choose, hide it behind a first-party interface so swapping implementations later is a one-day change rather than a migration.