I'm creating PHP MySQL real time chat app. A friend told me It is very bad to use PHP for real time apps & that would kill server CPU.
I know that PHP isn't the proper choice but i wanna get some advices to make the performance better with using PHP for real time chat apps.
I also wanna know why some developers prefer using PHP7 over NodeJS/Socket.IO/GO/..etc ?
Thanks,,
I would prefer Nodejs + Socket for realtime chat application because of one reason that it will be completely Javascript from Browser/Mobile to server and if NoSql is database than upto database as well.
But your point of PHP7 vs Nodejs/Socket left me with a question and to get the answer I came across this blog. This might help you as well. Its too long to explain it here.
PHP7 vs Nodejs
From what I've read this should be possible due to the modular nature of Laravel, but I need assurance from people with more Laravel experience:
I have a very large (500k loc) ancient PHP app. So ancient that some parts of it date from PHP3 times (ca. 2000, PHP4 was released already but PHP3 was used for backwards compatibility reasons).
Refactoring this is a huge project, and the only way to reasonably do it is in parts. Replace this part, then that part, etc. Fortunately, the "ancient" part comes in handy as no framework was used and basically every page is its own script, with a few central libraries for shared functionality.
Is it possible to spin up a Laravel app that can route new/refactored pages to the new site and everything else (wildcard if possible) to the ancient code? All data is stored in a database, so there will be no sync issues between them except for user authentication and session info.
Is it possible to get eloquent running on an ancient DB design or to refactor the DB in such a way that it works for both? There was a previous attempt to move the DB interface to Doctrine which from what I know was aborted after partial success (i.e. many DB objects are accessed through Doctrine, but there is also a lot of straight SQL code in parallel).
It's a huge mess, but the software in question is still being used and successfully so and a previous attempt to replace it with something else has already failed.
additional details:
Thanks #maiorano84 for good questions:
First, does your legacy application have tests?
Negative on that. PHPUnit was released in 2004. At that time, this app had already been in production for four year.
Second, are you able to get it to work on a more recent version of PHP?
Yes, the current codebase is running on PHP 5.6.33 - it has been maintained throughout the years, and a major update was made on the transition between PHP 4 and PHP 5.
If it runs on PHP 5.3+, you can use Instant Refactoring
I'm an author of Rector, a tool that can migrate huge amount of PHP files in a few seconds. E.g. upgrade PHP 5.3 to PHP 7.4, upgrade Symfony 2.8 to 4.2 or migrate from Nette to Symfony (read the case study).
1. Install Rector
composer require rector/rector --dev
2. Create rector.php with PHP sets, since you have old PHP code
// rector.php
use Rector\Core\Configuration\Option;
use Rector\Set\ValueObject\SetList;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator):
void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SETS, [
SetList::PHP_52,
// use one set at a time, as sets build on each other
// SetList::PHP_53,
// SetList::PHP_54,
]);
};
3. Then run Rector on your code (e.g. /src directory)
vendor/bin/rector process src
You can also write your own rules, so you can convert the code to Laravel/MVC approach. The idea is to write one rule, that e.g. converts 100+ files to controllers.
Read more on Github repository.
Is it possible? Yes.
Is it going to take a short amount of time? Absolutely not.
With any kind of legacy codebase, you're going to need to take the time in figuring out all of its moving parts and figuring out what portions are going to need to change in order to even be able to work on a modern platform.
The most recent version of Laravel requires PHP 7.1.3, so even attempting to just dump the entire codebase into a Laravel application is very likely going to result in failure.
First, does your legacy application have tests? These can be unit tests, integration tests, or functional tests. If not, and you want to be able to modernize your application without breaking things in the future, then you're going to want to write tests to ensure that nothing breaks as you begin upgrading. This alone can take a long time, especially with a codebase that makes it difficult to even test in the first place. Having a fully tested application will allow you to see which tests begin to fail as you start reworking your application, so this information will be extremely valuable.
Second, are you able to get it to work on a more recent version of PHP? If this code is already in production, then you're going to need to use some hardware virtualization through Vagrant, or better yet, containerization through Docker to get a local installation up and running without breaking your production code.
Once that's ready, then you should be able to begin refactoring. Taking entire pages of code and dumping them right into a Laravel application is not going to work straight out of the gate. You're going to want to start smaller. Find all of your moving parts, figure out what each one is responsible for, and encapsulate them in classes with the appropriate methods.
Use Composer's PSR-4 Autoloader to help remove all of those extra include and require statements and load your new classes throughout the application.
Use a decent Router to change all of your URLs into SEO-friendly paths and have a clearly defined entrypoint for all requests.
Move all of your business logic out of webroot: Create a /public folder in which you have just your index.php entrypoint and all public-facing assets (images, css, javascript, etc.). Since all requests are all being routed over to this file by this point, you should be able to process the request and return your response.
Once you get to a point where you've actually gotten the application into a system of well-defined components and modules, then migrating over to Laravel - or any other well-established framework - should be much easier.
This is going to take you a long time if you plan on doing it right. Hopefully this helps, and best of luck to you.
Refactoring is of course possible, but I have some doubts, if it is doable partially in this case. By partially here, I mean that, parts of the app will run sometimes on old and sometimes on new code in production.
I did this once for and old project, but not as ancient and big as yours.
In my case it was custom app (without any framework) running on php 5.3 and I was converting it to Laravel 4.2.
I must admit that there are some real challenges on the path.
This is only tip of the iceberg, but I'll try to name few of them, from what I remember:
PHP version compatibility or rather incompatibility in this case. You can rewrite existing code to run on latest PHP 7 versions. That might be a lot work however - not used in the end.
Routing and asset handling - you need to check if you can modify urls so they can fit into Laravel routing engine. It may be really hard, especially if old app is using Laravel standard paths and if you don't want to break google indexing for example. I have also seen systems with custom generators for urls which were then heavily used in views. Trying to do perfect match for these routes would be a nightmare.
Authentication. Changing auth must be done in one step, cause adapting Laravel to properly work with sessions from old system (although doable) will clutter new code.
Database. You will be lucky if database is well designed, but I don't think it will be even close to Laravel Eloquent conventions. Although you can run it on Laravel without any DB schema modifications, your new code will also get bloated in your new app. This and other things can be refactored again in complete system, but it's another load of work.
Considering amount of all possible, not optimal workarounds, in order to have properly designed app (built with best practices), probably it will be better to rebuild from scratch.
Hope it helps a bit...
I have to built a multilayer game using web-sockets. For this I have a a shared web server with Apache. Browser is not an issue I am building for modern browsers only.
I tried few example PHP and web-socket source code but no luck.
What do I need to do?
And also how to enable the PHP socket_create function? Already enables php_sockets extension in the php.ini and also the php_sockets.dll exists in the extension directory.
When I call socket_create function php says that this function is undefined.
Any kind of help is appreciated.
Thanks
It seems that the command prompt was using a different configuration file for PHP.
Apache (or from the WAMP's interface) uses a php.ini that is located at:
[WAMP_DIRECTORY]\bin\apache\Apache2.2.21\bin\php.ini
If you will open this file, you may notice that the line extension=php_sockets.dll is already commented out.
Unfortunately, the CLI or command line interface is using a different configuration file which is located at:
[WAMP_DIRECTORY]\bin\php\php5.3.8\php.ini
In order to resolve it, you should comment out the line extension=php_sockets.dll and save it. Run the program after to see if the websockets again are already up and working.
If you can guarantee WebSocket support in the browser then use Ratchet. It won't run within Apache, but as a separate process.
There are other options available too - see the realtime web tech guide.
Questions related to WebSocket + PHP have been asked a number of times on SO. I'd recommend doing a search for best solutions and known gotchas when using Apache, PHP + WebSocket. Here's are a couple of good starting question with some additional links in the answers:
Is native PHP support for Web Sockets available?
Efficient reloading data / pushing data from server to client
I have inherited a Windows Server and I have to deploy a django app on it.
Have anyone tried to benchmark http servers with django support on this platform?
Which one is fastest?
Use-case of my application would be:
not so much writes to db
heavy usage of admin panel
display tons of results
Have you looked at either wamp or xampp? They both deliver Apache/MySQL/PHP-and-Perl on a Windows platform. But you need more because neither includes Python. See this SO thread for how to proceed from there. Note, you may encounter problems. See this SO thread for an example.
Ps. Personally, I would just get a an account that supports Django (e.g. webfaction.com) and not screw around with this.
I run a Django site on Windows using Apache. I've posted a write up about some of the hurdles that you're going to face.
I am currently hosting my site on my computer on WAMP, however I am looking to take it live. The problem is that it uses both CodeIgniter and PHP 5.3. It will not however, draw very much in the way of traffic to start. Is there some way I can get greater control of my server (so that I can use 5.3 and CI) without having to pay the expense of VPS? And which host would you recommended?
ovh provides a way to select the php version you want. The english page is a little bogus, so I give the french one: documentation.
So yes, they let you choose the php version you want, even php6 by just changing a value in an htaccess file. I have a running CI site there, and it runs very well.
SO I suppose this must exists elsewhere.
I don't have experience running Codeigniter on shared server hosting, but I don't see any reason why you couldn't upload CI and run it on any host as long as it meets the requirements.
Codeigniter 1.7.2 only requires PHP 4.3.2, but of course you'll want to find a host that at least has the option of running PHP 5. I'm not going to recommend any hosting companies, but if you need 5.3 then you can do a web search for PHP 5.3 hosting or ask companies what versions they are running.
A VPS is going to be more expensive, and might take some configuration on your part.
One of your better bets is DreamHost.
Here's a guide on how to install PHP 5.3 on dreamhost:
http://wiki.dreamhost.com/Installing_PHP5#PHP_5.3
One.com is very cheap and runs PHP 5.3.3. They do have carrier servers - so it's great latency for nearly everyone. They have memory limitations since it's shared hosting and you can't install extensions, but except for that it's a great service, great uptime and with a very low monthly cost.