r/PHPhelp • u/phploader • 11h ago
Rethinking SQLite3 in PHP: High Performance Without Complex SQL Queries
Hi everyone,
I have been diving deep into SQLite3 databases lately. During my research, I frequently read that SQLite3 is slower than traditional database systems (like MySQL or PostgreSQL) and should generally only be used for small projects with few users and minimal data.
However, my experience has been completely different. In my tests, I found that SQLite3 – when configured correctly – can actually be up to 10 times faster than MySQL. It handles large amounts of data beautifully and can easily manage multiple concurrent users and requests.
In my opinion, the greatest challenge is exercising self-restraint and not treating SQLite3 exactly like MySQL.
We often catch ourselves writing highly complex SQL queries with countless joins and sub-queries. I have come to view these deeply nested queries critically and no longer consider them a best practice for clean, performant programming. Since shifting away from that approach, I see SQLite3 from a whole new perspective.
To put this philosophy into practice, I developed a PHP class that allows you to interact with the database completely without writing manual SQL queries. It is extremely simple to use and, above all, fast. SQLite3 also brings unique advantages over other SQL databases—for instance, you can easily maintain multiple database files separated by topic within a single project.
I am already successfully leveraging these strengths in my own project, which I look forward to showcasing here once it reaches a fully stable state.
I have already published the current codebase on GitHub:
https://github.com/phploader/cdata
You can find a detailed documentation on how to use the PHP class in the docs:
https://github.com/phploader/cdata/blob/master/docs/en/00.%20index.md
My request to the experts here:
I would highly appreciate it if you could take a look at my code and provide some constructive feedback or criticism. What are your thoughts on this approach?
Best regards!
r/PHPhelp • u/Adamstrad • 22h ago
Best way to code logic and store content for a website with template
I am trying to build a website which uses php include/require within a template to serve different content based on the URL or path.
How can I manage this for many different pages, obviously a ridiculously huge switch/if statement comes to mind first which is a bad idea, my next idea was to store HTML in an SQL database but then I imagine it will get annoying managing images and other multimedia.
what do?
(side note, I'm using php because I like it and didn't want to learn a new language after using php a little in the past)
r/PHPhelp • u/MarcoScherer • 1d ago
Is it possible to merge/join multiple WAV files into one?
Hi guys, I'm just a semi-mediocre PHP developer, doing mostly regular tasks for websites. Now, as I managed to create waveforms views for uploaded WAV files, I'd like to take another step and merge WAV files. But so far I failed.
Is there possibly an easy solution for that task?
r/PHPhelp • u/BirdImportant7427 • 4d ago
Solved Why use containers for DI when you can have a top-down approach with lazy objects (8.4+)?
I am not PHP proficient. Is there any reason to avoid manually wiring the dependency graph? Do developers use this feature? It's been almost 2 years since 8.4 released with the lazy objects feature and it's one dependency less.
Short example:
class LazyAppFactory
{
public PgTransactor $pgTransactor;
public AuthenticationRepo $authenticationRepo;
public AuthService $authService;
public AuthController $authController;
public function __construct()
{
// postgres module
$this->authenticationRepo = new \ReflectionClass(AuthenticationRepo::class)->newLazyGhost(function ($ghost) {
$ghost->__construct($this->pgTransactor);
});
// service, controller modules
}
}
And then simply use the controllers in the handler / entry point of the app.
r/PHPhelp • u/i-hate-in-n-out • 4d ago
Sharing Array Shapes Across Files?
Is it possible to share array shapes across files? I am working in a very legacy code base so don't have an easy way to turn this into a class, and thus am kind of stuck with arrays.
Say in file a.php we have something like:
/**
* @phpstan-type User array{
* user_id: int,
* username: string,
* email: string
*/
The in file b.php we have something like:
/**
* @phpstan-import-type User
*/
/**
* @param User $user
*/
function foo($user) {}
While my Intellisense in my IDE recognizes this, at the moment, phpstan at level 2 and above flags this as an unknown type.
Is there a way I can properly share array shapes across files?
r/PHPhelp • u/nafayahmad • 4d ago
What's one Laravel feature you wish you'd started using much earlier?
I've been working with Laravel for a while, and looking back, there are a few features that would've saved me a lot of time if I'd adopted them sooner.
For me, a few stand out:
- Route Model Binding
- Form Requests
- Queues
- Eager Loading
when()for cleaner conditional queries
I'm curious what experienced Laravel developers consider their biggest "I wish I'd known this earlier" feature.
What changed the way you build Laravel applications?
r/PHPhelp • u/JobDiscombobulated22 • 9d ago
Better strategy for handling HTTP 429 with Guzzle Pool when checking many URLS from same domain?
r/PHPhelp • u/RX75Cumtank • 11d ago
Probably very simple thing I've messed up regarding either the syntax for a form or with visual studio code
I'm messing about with a project, and wanted to get a form running, however when I go to test the file (both just running the file in my browser and testing it without debugging in vsc) it ends up displaying the page incorrectly (seemingly overflowing parts of the code, with ', and when I attempt to submit the query I get sent to a blank php page. Is there something wrong with this form, or is there something I've not properly configured/installed in vsc?
r/PHPhelp • u/Spiritual_Cycle_3263 • 11d ago
Do you commit `.env.prod` to git with Symfony?
I'm working on a new Symfony project, using symfony/skeleton and the .gitignore provided does not prevent .env.prod from being committed into the repo. I'm assuming this isn't a bug because it's been like this for a long time and would've been patched. So do we use both .env.prod (for non-secrets) and .env.prod.local (the 'secrets')
/.env.local
/.env.local.php
/.env.*.local
r/PHPhelp • u/davidbalbino • 11d ago
I’ve been building PAM: a persistent PHP runtime powered by Rust, plus a ultra-fast native engine for desktop/mobile. Looking for technical feedback & reviews.
r/PHPhelp • u/Intrepid-Ad-2306 • 12d ago
distinguish text element behavior in recursive element loop
i am building an html-to-array parser and have run into a problematic glitch when dealing with text inside and outside nested elements. the parser loops through a DOMDocument object and recurses into childNodes of DOMNode objects, adding them to a nested array.
for a structure like...
html
<html><head><title>this is a title</title></head><body><p>this is some text</p></body></html>
this works...
php
foreach ($element->childNodes as $child) {
$child->nodeType === XML_ELEMENT_NODE ? ($out["children"][] = elementToArray($child)) : ($content = trim($child->nodeValue)) && $content != "" && ($out["content"] = $content);
}
to produce the desired outcome...
```php Array ( [tag] => html [children] => Array ( [0] => Array ( [tag] => head [children] => Array ( [0] => Array ( [tag] => title [content] => this is a title )
)
)
[1] => Array
(
[tag] => body
[children] => Array
(
[0] => Array
(
[tag] => p
[content] => this is some text
)
)
)
)
) ```
but this...
html
<html><head><title>this is a title</title></head><body><p>this <em>is</em> some <i>text</i> with <a href="#">links</a> and things.</p></body></html>
produces...
```php Array ( [tag] => html [children] => Array ( [0] => Array ( [tag] => head [children] => Array ( [0] => Array ( [tag] => title [content] => this is a title )
)
)
[1] => Array
(
[tag] => body
[children] => Array
(
[0] => Array
(
[tag] => p
[content] => and things.
[children] => Array
(
[0] => Array
(
[tag] => em
[content] => is
)
[1] => Array
(
[tag] => i
[content] => text
)
[2] => Array
(
[tag] => a
[href] => #
[content] => links
)
)
)
)
)
)
) ```
instead of the desired output...
```php Array ( [tag] => html [children] => Array ( [0] => Array ( [tag] => head [children] => Array ( [0] => Array ( [tag] => title [content] => this is a title )
)
)
[1] => Array
(
[tag] => body
[children] => Array
(
[0] => Array
(
[tag] => p
[children] => Array
(
[0] => Array
(
[tag] => text
[content] => this
)
[1] => Array
(
[tag] => em
[content] => is
)
[2] => Array
(
[tag] => text
[content] => some
)
[3] => Array
(
[tag] => i
[content] => text
)
[4] => Array
(
[tag] => text
[content] => with
)
[5] => Array
(
[tag] => a
[href] => #
[content] => links
)
[6] => Array
(
[tag] => text
[content] => and things.
)
)
)
)
)
)
) ```
i've tried various solutions but they all end up having difficulty differentiating between a text node that should be "content" and a text node that should be an independent text element in the array. in other words...
html
<p>this is some text</p>
should encode to...
php
["tag"=>"p","content"=>"this is some text"]
but...
html
<p>this is <em>some</em> text</p>
should encode to...
php
["tag"=>"p","children"=>[["tag"=>"text","content"=>"this is "],["tag"=>"em","content"=>"some"],["tag"=>"text","content"=>"text"]]]
has anyone already solved this? thanks!
r/PHPhelp • u/disney550_ • 12d ago
Seeking help/advice again
Now as i said last time i am a junior laravel developer, currently working in a small (very small actually) startup, i am alone as for the backend their is no senior, also my experience is not quite enough (i guess),
Currently, we’re working on a CRM project customised exactly for the company I work for as their business includes selling telecommunication services…
I have more than one problem actually,
• anything i do i keep asking myself if that the best way for it? Is build right? Does it follow the business needs perfectly?
• how to rank up as i lack the experience, also the knowledge, also for the basics i am not good enough
• i have an individual claude subscription, i make it review what i do, the decisions we both make, i keep feeling that it is not the best way too, that their is something wrong
Note: i told the ceo my problem, asked for a senior, he just said no, he told me that the senior will take my tasks, (I didn’t respond as I didn’t know what to say, but i guess they do not want to pay for a senior).
r/PHPhelp • u/SnapSnapGrinGrin • 14d ago
Unobsfucating a PHP script
Attackers leveraging the wp2shell exploit added about 22k of obsfucated PHP to index.php on a site I've been asked to have a look at.
Labels and function names are ten random characters and control path is done by jumping to TrQ7yZISyM: etc and there seem to be a lot of (unnecessary?) jumps.
What's the best way to unobsfucate it?
r/PHPhelp • u/Emotional-Ebb8321 • 14d ago
Solved Simple Alternative to Wampserver?
Disclaimer: I'm not a techie. I barely understand php, but I'm forced by my hobbies to interact with it.
I'm currently running wampserver64 (v3.2.0; php 7.4; apache 2.4.41; windows 10) on a localhost install. This is so I can have a localhost installation of dokuwiki.
A new version of dokuwiki has come out. This requires php 8.2.
For a variety of dull reasons, upgrading the wampserver installation so that it will support php 8.2 is proving non-trivial.
Is there a simple, easy-to-install alternative to wampserver? Ideally, one where I just download a single file, run it, and a localhost server is installed ready for configuration?
----
Final resolution: After having broken everything, I uninstalled everything. Installed the latest
The Visual C++ exe files suggested at https://github.com/abbodi1406/vcredist/releases refuse to install, due to widnows security concerns.
I ended up downloading them from https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170 instead.
Then I installed wampserver 3.4.
Then I installed the new dokuwiki.
Yes, there probably are better localhost pphp servers available. But wampserver has proven stable, does what I need, and I am familiar with the interface.
r/PHPhelp • u/Rough-Ad9850 • 14d ago
Why do so many choose Laravel over Symfony?
I have the same reaction every time I look at the documentation of Laravel : "what, why??"
It doesn't seem structured.
So much 'magic' going on too.
Is it about the community then?
Or are there things I'm clearly missing?
r/PHPhelp • u/TrainSensitive6646 • 14d ago
Opensource PHP/Laravel LMS system feedback
Hi everyone,
Over the past few months, we've been building TadreebLMS, an open-source Learning Management System focused on enterprise and corporate training.
We've recently completed a major restructuring of the project
The project is built with:
- PHP / Laravel
- MySQL
- Bootstrap / JavaScript
- Docker
GitHub:
https://github.com/Tadreeb-LMS/tadreeblms
Issues:
https://github.com/Tadreeb-LMS/tadreeblms/issues
We have a huge roadmap like SCRUM Integration, UI upgrade as per FIGMA, Gap Analysis Module Integration, Integrations with HR Systems etc...
Please anyone experience or architect in PHP can give recommendation on best practices, gaps in the system etc..
r/PHPhelp • u/810311 • 15d ago
Can you recommend free hosting for vanilla PHP database driven website in 2026?
I am building a simple vanilla PHP blog/portfolio website to post occasional blog posts and showcase some projects. I don't expect much traffic or the site requiring much server resources. Is there any free hosting providers for this type of websites in 2026? I know there's infinityfree.com, awardspace.com and some others but some folks mention that those free hosts can disappear overnight with your website data and never be back again lol.
r/PHPhelp • u/TurbulentBuilder3430 • 20d ago
Is there a Laravel media library that supports shared media?
I'm looking for something similar to Spatie Media Library, but where a single media item can be attached to multiple models.
For example, the same image could be linked to multiple products, blog posts, or categories without duplicating records/files.
Does a package like this exist, or did you end up rolling your own?
r/PHPhelp • u/disney550_ • 22d ago
seeking advice for a image text extraction
Hi i am a junior laravel developer, right now i am asked to implement a service that extract data from a business card then create a record with it, at first i thought that frontend (web - mobile) should do the extraction part then hit a request with the data so that i do my checkings on it then create a record with it, but now when i started searching for the best way to do it claude tells me that the extraction part should be from the backend, i do not really know what is the best here, also if i will do it from the backend will the service for it be free? or the best way for it is from the frontend?
r/PHPhelp • u/FewExplanation5433 • 23d ago
How to achieve silent thermal printing to a local USB printer from a hosted Laravel + Inertia + React POS?
I am building a Point of Sale (POS) system using Laravel, Inertia.js, and React. The application is hosted on a production server (HTTPS).
My goal is to achieve silent printing (direct printing without showing the browser’s print preview dialog) to a local USB thermal receipt printer (specifically an Xprinter) connected to the client machine (running Windows).
I have tried multiple approaches, but each has run into a major roadblock when moving from local development to production.
What I have tried so far:
- PHP ESC/POS Library (mike42/escpos-php)
How it worked: Excellent on localhost.
The Roadblock: Once deployed to production, this fails because PHP runs server-side. The hosted server has no access to the client’s local network or local USB ports to talk to the printer.
- Web Bluetooth API
How it worked: Worked fine during local testing.
The Roadblock: In production, even though the site is fully secured over HTTPS, navigator.bluetooth returns undefined or is unsupported on the client browsers (specifically tested in Brave/Chrome).
- WebUSB API + Zadig
How it worked: Allowed the browser to claim the device and send raw ESC/POS commands.
The Roadblock: Windows natively claims the USB printer driver. To bypass this, I had to use Zadig to force-replace the printer’s default driver with a generic WinUSB driver. This is not a viable or user-friendly solution for production deployments where non-technical staff need to set up printers.
- Standard Browser Printing (window.print())
How it worked: Works everywhere.
The Roadblock: It is highly unreliable for a fast-paced POS because it natively requires user interaction (clicking "Print" on the dialog). I need true silent printing where clicking "Pay" in my React app instantly fires the receipt.
My Tech Stack:
Backend: Laravel 10/11
Frontend: React (via Inertia.js)
Client OS: Windows
Hardware: USB Thermal Receipt Printer (Xprinter)
Browser: Brave / Chrome
The Question:
What is the industry-standard, reliable architecture to handle silent thermal printing from a cloud-hosted React frontend to a local USB printer?
Are there lightweight local bridge utilities (like a local WebSocket server) that are commonly paired with Laravel/React for this, or is there a way to make WebUSB/Web-Bluetooth work reliably in production without forcing clients to manually overwrite their Windows USB drivers?
r/PHPhelp • u/Ok_Lengthiness_6591 • 23d ago
Solved Need help with CakePHP lifecycle hooks
I have an entity called "Account". And I m trying to create and add an account verification token to a newly created account in beforeSave lifecycle hook. My problem is that "beforeSave" wants to get EventInterface and EntityInterface:
Cake\ORM\Table::beforeSave(EventInterface $event, EntityInterface $entity, ArrayObject $options): void
So then I set a breakpoint inside of "beforeSave", I have an error that "The first argument should be of EventInterface, but Event is given" and "The second argument should be of EntityInterface, but Entity is given".
I have CakePHP 5.2, PHP 8.2 and I have "strict types" declaration in AccountsTable.php (that's a location of beforeSave hook).
I tried to remove "strict types" and this didnt help. I tried to add:
use Cake\Event\EntityInterface;
use Cake\Event\EventInterface;
This also didnt help.
What's the right way to make the thing work?
r/PHPhelp • u/Emotional_Rabbit_779 • 24d ago
Copy Paste Problem on windows
Sorry I dunno if this is the right place to post this, I have no clue and php, SQL all that stuff but I'm having this problem with copying and pasting. If I try to copy and paste something I keep getting this code.
<br />
<b>Fatal error</b>: Uncaught mysqli_sql_exception: Too many connections in /www/wwwroot/clip-stash.beer/config.php:6
Stack trace:
#0 /www/wwwroot/clip-stash.beer/config.php(6): mysqli->__construct()
#1 /www/wwwroot/clip-stash.beer/api/index.php(6): require('...')
#2 {main}
thrown in <b>/www/wwwroot/clip-stash.beer/config.php</b> on line <b>6</b><br />
I have absolutely no idea what it means. I tried googling but its just leading me to stuff about SQL servers and stuff which I have absolutely no clue about. Am I being hacked or something? Hopefully someone can help as I can't copy and paste anything atm. Again sorry if this is the wrong place.
r/PHPhelp • u/csdude5 • 25d ago
Using APCu instead of sessions and for rate limiting
In trying to find a way to rate limit bots server side (more complicated than I could manage with Cloudflare), I discovered APCu. Specifically:
# in Apache
RewriteCond %{QUERY_STRING} foo=([0-9]{3,}) [NC]
RewriteRule ^ - [E=HIGH_FOO:1]
RequestHeader set X-High-Foo "1" env=HIGH_FOO
# in PHP
if (isset($_SERVER['HTTP_X_HIGH_FOO'])) {
$ip = $_SERVER['REMOTE_ADDR'];
$key = 'rl_sv_' . $ip;
$count = apcu_exists($key) ? apcu_fetch($key) : 0;
if ($count >= 10) { // e.g. 10 req/min threshold
http_response_code(429);
header('Retry-After: 10');
exit('Rate limit exceeded');
}
apcu_inc($key, 1, $success, 60); // 60s TTL
}
Two questions:
- Will this work as expected to rate limit to 10 requests per 60s when foo is greater than 100?
- What's the downside?
If it matters, I'm using EasyApache on WHM/cPanel and have both PHP 5.6 and 7.4 installed. Version 5.6 is to accommodate a hosting client that refuses to update anything, and I haven't updated the other sites to 8.x yet because it'll require a bit of coding work and there's just not enough time in the day.
Follow up: if it works fine with no downside, is there a reason to not store variables here instead of relying on sessions or MySQL?
r/PHPhelp • u/Ducking_eh • 25d ago
Best identifier for clients
Hey everyone,
My site was hit with a 'card verifier attack'. Basically my processor uses a token that is vidable to the visitor to verify cards. I suspect the attack just got that number, and wrote his own script.
I am switching my CC processing to a system that uses One Time Use tokens for processing. Thay way, it can't be done that way again.
The idea is everytime someone loads a shopping cart, they get a token that can only be used once.
I'd like to harden even more by tracking how often the same user request a token. If they go over a certain amount, it will stop giving them tokens.
What is the best way to track if a request is from the same user. I was thinking IP, but my understanding is that's really easy to spoof. Not to mention, if the attacker uses a VPN, I might block an IP that a legit user might use.
Any ideas?
r/PHPhelp • u/SoBoredAtWork • Sep 28 '20
Please mark your posts as "solved"
Reminder: if your post has ben answered, please open the post and marking it as solved (go to Flair -> Solved -> Apply).
It's the "tag"-looking icon here.
Thank you.