Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there any way to let the cpu handle some operations in PHP (quite like openCL) but is available in native php (without having PHP-openCL implemented)?
/E:
What i mean:
I am coding some php cli scripts
Everything you do in php (variables, etc.) will be cached in the ram. But you still can access the RAM directly (shmop - Link), which makes it way faster. (This is an example to access deep system resources, i just want to know if there are ways to access other deep system resources)
I want to acces the CPU directly for having speed up some operations by doing so. (in context of multithreading (pcntl_fork and running inside an endless while-loop in php cli script). Is there a way to skip the c-handler (dunno if this is the right expression).
OpenCL was just an example =)
shmop is not "accessing memory directly" (it's sharing memory) and "bypassing the C layer" is not "accessing the CPU more directly".
The only thing that may remotely make sense is that you wish to code in ASM directly, instead of writing code in a higher level language which gets compiled down to machine code eventually. This is useful if you think you understand the CPU better than a C/PHP compiler and can write more efficient code for it (in your case, I'd have my doubts, to be honest). If so, you'll have to write an external application in said low-level language and invoke it from PHP. In C and some other languages you could write inline-ASM, but PHP doesn't support that.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I was wondering if someone could give a high-level answer about how to track functions which are causing a slow-down.
We have a site with 6 thousand lines of code and at times there's a significant slowdown.
I was wondering what would be the best way to track the source of these occasional slowdowns? Should we attach a time execution tracker on each function or would you recommend something else?
It's a standard LAMP stack setup with PHP 5.2.9 (no frameworks).
The only way to properly track down a why and where a script is slowing down, is by the use of a profiler.
There are a few of these available for PHP. Some of which requires that you install a module on the server, some which uses a PHP-only library, and others again which are stand alone.
My preferred profiler is Zend Studio, mainly because I use it as my IDE. It has the benefit of being both stand-alone, and to be used in the conjunction with server-side modules (or the Zend Server package). Allowing you to profile both locally, and on production systems.
One of the easiest things to look for, however, are SELECT queries inside loops. They are notorious for causing slow-downs, especially when you have a more than a few hundred records in the table being queried.
Another if is you have multiple AJAX calls in rapid succession, and you're using the default PHP session handler (flat files). This can cause the loading time to increase significantly because the IO-operations are locking. This means that it can only handle one request that uses session at a time, even though AJAX is by its very nature asynchronous.
The best way to combat this, is to use/write a custom session handler that utilizes a database to store the sessions. Just make sure you don't saturate the DB connection limit.
First and foremost though: Get yourself a proper profiler. ;)
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am developing an App on a Raspberry Pi using PHP and mySQL. After couple of weeks of development I have noticed that in some cases the App runs slow and then I try to optimise the code related (e.g. too many loops within loops, or loading of static images dynamically is really slow on RPi). Usually the slow-downs would not be felt at all on a more powerful hardware, but I decided that those slowdowns would be noticeable when the server hardware resources are maxed-out.
The question:
Would the application performance optimisations on a Raspberry Pi allow me to achieve better results on a multi-code multi-socket Xeon server later? e.g. would I be able to reach more hits per second before maxing out the hardware resources when I take this approach by developing my App on a less powerful hardware? Or is it just a waste of time and the performance gains are not worth it?
I am asking this because the architecture of RPi and Xeon is very different and whatever I am doing might be a waste of time. As I do not have a Xeon server at the moment, I am not able to compare and prove my point above at all. :)
Thank you!
It depends upon what type of optimizations you are doing. Portability across different hardware all comes down to the architectural independences of the abstractions you are using (e.g. language, compiler, libraries). My understanding of PHP is that it works at a very high level as an interpreter intended to be as portable as possible. So it is already abstracted from the hardware.
My guess is that your optimizations will carry across to the Xeon. I figure you're doing algorithmic and code optimizations, such as researching better methods of doing something, replacing loops with more efficient code, using better data structures, and getting rid of unnecessary and redundant calls. All that will help on any machine.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I do quite large project for a client and I would like (somehow) to secure code form event that mid dishonest client was not going to pay me for the work. :)
The contract is written that the project must provide application with a sources.
So far I mostly been writing in .NET where I was protecting myself against such an eventuality in way that I was creating class witch get POST some parameters with shutdown application. This class was thrown into a dll witch was already compiled, so no one could change the source.
Is there a similar possibility in PHP? I can do the same thing (as in .NET case) but clever customers with access to PHP can find above class and I just cut it.
Maybe it is some other way to secure myself?
Suturing of the database also eliminated for similar reasons as above.
PHP is an interpreted language; as a result, it doesn't compile your code. Your best bet is to stick with .NET, where you can compile the functional part of the application into a .dll, or use Java and compile it into a bytecode.
PHP wasn't built for compiling.
What you can do is probably host the application on your server till the client has made a payment, and then upload it to the client's server.
Or you can make it downloadable from your server (only after payment), along with configuration scripts that is configurable by anyone with a few clicks of the button; something similar to the way some of the PHP frameworks (e.g. WordPress) work.
You can protect your code with Zend Guard (http://www.zend.com/en/products/guard/).
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Okay so I've running so pretty large queries on my site and its been running up the mysql resources. My admin questioned whether I've tried different php accelerators but I've never installed one before. So I did some research on it, and I'm curious do I need to make any modifications to my actual php codes or do I just install an accelerator and let it take effect? I need ways to optimize my load and reduce the amount of resources being used on the server.
"PHP accelerators" are opcode caches; they save the server from having to re-interpret PHP files on every request. The savings is somewhere in the realm of 1% of CPU load, and it won't help you one bit if your problem is with the database's resource usage.
Most PHP accelerators work by caching the compiled bytecode of PHP
scripts to avoid the overhead of parsing and compiling source code on
each request (some or all of which may never even be executed). To
further improve performance, the cached code is stored in shared
memory and directly executed from there, minimizing the amount of slow
disk reads and memory copying at runtime.
Source: http://en.wikipedia.org/wiki/PHP_accelerator
Sounds to me like you need to accelerate your SQL queries, not your PHP code.
Here are a list of PHP accelerators that you can evaluate and install
http://en.wikipedia.org/wiki/List_of_PHP_accelerators
I've used APC, which I believe is one of the most popular PHP accelerators. One thing that it does is basically cache function calls and arguments, so that subsequent calls to the same function with the same arguments will have its return value cached, and not have to recompute everything.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm working on a rather intensive rewrite and given a choice of the following options:
JSP / Java running on Tomcat
PHP running under Apache
Ruby (running under I'm not sure, ROR?)
A couple of basic questions I would like to know about the above.
Speed is a concern. We have a MongoDB backed database, so we shouldn't need to be waiting on the database for information, but the frontend needs to be as fast as possible. The common saying speed isn't a concern doesn't really apply here. If you're processing 500k+ objects in one request it needs to be fast.
Scalability is another concern. Suppose our database blossoms out of control. Which (of the above) would provide the easiest method of handling this?
What are common downsides of Tomcat / JSP and Ruby? Is parallel processing easy to do with PHP or Ruby?
The goal is not to save money but to build a solid, fast, scalable system to continue development on for years to come.
I'll be honest, I'm a former Java developer (not JSP) turned PHP developer. My preference for anything is PHP but I also am a big believe in using the right tool for the job. The team is competent enough to write this is anything that we
Seems like any of them would be acceptable based on the limited info so far. The important things I've begun to consider when launching new projects are more about the ORM and framework than about speed. For every extra 40 hours of developer time I have to spend on a project I can provision and operate a new server for 1 year.
If you have developers that are better versed in the APIs for a particular language, that alone could (potentially) make your decision. If you can parallelize 500k things across 10 servers, and choosing language (and API/libraries) A over B will save you 10 weeks, then that is your breakeven point. Similarly, if one set of things is 2x as slow, and having 2 servers instead of 1 could double your processing speed, then it will only take 1 week of extra fighting in the "faster" language before all your performance gains are wiped out due to longer development time...
Ended up going with Play!
Reasons:
Quick startup
No redeploying / packaging
Straight forward MVC pattern
Groovy template / inherited views
Drop-in support for dependencies as JAR files
Development was never hindered by it. No one had to learn anything new besides where to put the controllers / models / views.