I am writing an application for image processing. I am just wondering which programming language would be the best fit. Python or PHP. This process is system based not web based so I am just thinking if Python could be of more help.
Let me know your thoughts!
Python has stuff like SciPy and PIL so probably Python.
Here is how people use it:
Peak detection in a 2D array
How can I improve my paw detection?
One cannot suggest much without knowing the kind of image processing you have in mind.
If you just want to do some generic rotate/resize/etc then I guess there isn't much difference.
If you want to do something more complex, then study the libraries and decide which fits best for your particular task.
If you want to do something really custom, then C or similar language might be a better fit for the task.
Possibly neither; it depends on what you want to do.
Both PHP and Python are scripting languages, and are therefore not suited for high-performance numerical routines (which most image processing requires). However, they both have a number of image-processing libraries available for them, the innards of which are probably written in C. These will be fast.
If these libraries do what you want, then fine. If you need to so something custom, then you're probably better off with C or C++ (or Pascal, or whatever) if speed of execution is of concern.
Python is more clean and readable.
For image processing there is the imageMagic library available for Python and PHP too.
If you want to do some other complex image processing, which cannot by done using a library and you still want to do it in Python or PHP, then Python is defenitely the answer as Python can be extended with C -- But, wait, you didn't mention programming in C, well, there is Cython! It would allow you to write Python modules which are afterwards compiled to C
It really depends on what you want to do with the images. You probably should just use a batch or similar script to run a command that does the processing your looking for.
Between the two languages, I would go with python. The command line interface for php is only a recent addition, while python was designed primarily as a scripting language, not for serving pages. For a console application, python is a better fit.
Related
I have a PHP script I'd like to compile into a standalone command-line executable for running on Linux.
Is this realistic? Are there compilers for this?
I know that there are PHP compilers around, but my question is oriented more to whether it is of advantage, and which is the best compiler to use.
Will it be faster or slower than running it through PHP? If it would speed up my script then that would be great, since it does a lot of processing (lots of loops and math) and takes an hour to run.
My understanding is that HipHop compiles to C++, not C, and that the process is quite easy. FaceBook has applied it to vast amounts of code.
I'm not sure you get a .exe, but OP only wants "faster". He might get quite a good speedup; HipHop compiled-code averages only a factor of 2 or so faster, but that's because much of PHP execution is really library calls. He might get pretty good speedup on his computation part, if the HipHop compiler can figure out what the data types are in the computation code. He might have to modify his code somewhat to make this clear to the HipHop compiler, by not using his computation varaibles for anything but computation but that should be only a minor source code change. I'd expect the HipHop site to contain hints about what to do to speed up HipHop compiled code along these lines.
All of this is educated guess based on what I understand and not actual experience. YMMV.
Well, compiling itself will add very little if your script runs for hours.
The best solution would be to use another language, C seems woud be the best choice.
you can try to translate your PHP to C using hiphop compiler but it is not the task I'd call easy
I am working on a project that requires reading text files, extracting data from them, and then generating reports (text files). Since there are a lot of string parsing, I decided to do it in Perl or Python or PHP (preference in that order). But I don't want to expose the source code to my client. Is there any good compiler for compiling perl/python/php scripts into linux executables?
I am not looking for a 100% perfect one, but I am looking for an at least 90% perfect one. By perfect, I mean the compiler doesn't require to write scripts with a limited subset of language features.
I'm sorry, it's simply not worth spending your time on. For any language you choose (from among the ones you listed), for any compiler/obfuscator someone chooses to come up with, I promise you I can get readable source code out of it (within an hour if it's Perl; longer if it's Python or PHP simply because I'm less acquainted with the implementations of those languages, not because it's intrinsically harder with those languages).
I think you should take a better look at what your goals are and why you want to work for a client that you're assuming a priori wants to rip you off. And if you still want to go ahead with such a scheme, write in C or Fortran -- certainly not anything starting with "P".
There does exist a Compiler for perl, called perlcc. I'm not familar with perl, but it looks like what you're looking for.
There are 3 options of encrypting Perl code:
Use PAR to create executable file with PAR::Filter::Obfuscate or PAR::Filter::Crypto
Use Filter::Crypto::CryptFile (will require some modules installed on target OS)
Turn into module and encrypt into Module::Crypt.
Also you can try B::C - it was removed from core Perl distribution and is now available on CPAN.
So far we've heard about perlcc and PAR with some obfuscation filters. These may work.
I have had very good luck with ActiveState's PerlApp which is part of their Perl Dev Kit.
It works well to bundle your code and hide it. You can try it for free, and it comes with some nice extras. Whether it is expensive or cheap depends on your perspective. For me, it was cheap. The cost in time of getting code hiding working and reliable with PAR or messing with perlcc was easily less than the price of the package. YMMV.
For Python You can call your code and give the *.pyc file to the client.
For linux an executable is something which has +x set, so there's no need to compile scripts. To hide your sourcecode you could use an obfuscator. This makes your sourcecode unreadable.
I've never used this, so I don't know how easy it is to setup, but you could use HipHop PHP to turn your PHP scripts into C++ code and compile them. (Assuming you choose to write them in PHP)
http://developers.facebook.com/blog/post/358
http://github.com/facebook/hiphop-php
For Python you can use cx.freeze. I have not used this but I believe that it basically bundles the .pyc into a zip file and adds an executable front-end.
Alternatively you could try compiling you Python code with Cython. this translates a modified version of the Python language into C code, which can then be compiled. This is normally used to write high performance extensions or interface with existing C libraries, but the latest version can also be used to make a complete executable.
I realize it's probably something strange, but here is what I have.
I have an application (handwriting recognition engine) written in C/C++. This application has Perl wrapper which was made by application's authors using SWIG. My website is written in PHP, so I'm looking for some ways to make PHP work with C/C++ application.
The only way I can think of now is to create a CGI script (perl script) which accepts POST request from my website (AJAX request), sends it to the recognition engine through it's Perl wrapper, gets the required data and returns the required data as a response to AJAX request.
Do you think it could be done this way? Are there any better solutions?
Thank you!
Do you think it could be done this way?
Yes, no reason it can't be done.
Are there any better solutions?
May be. If you intend to execute the perl wrapper as a system call to a separate Perl script, you don't need a separate CGI perl script. You can just do system calls from PHP in your site directly. Not a big difference but might help if PHP is more of your comfort zone for web stuff than Perl's CGI
OTOH, if the Perl script wrapper is a fairly obvious and simple set of API calls, and you feel comfortable with Perl CGI, a better soltrion is to port that command line Perl script into the Perl CGI script which uses the API internally, bypassing system calls.
For high-volume stuff, removing system calls is a Big Win performance wise, plus allows for much better and easier error handling.
What you are proposing is:
web client <-> Perl CGI script <-> Perl wrapper <-> C program
There is nothing particularly wrong with this approach, although it's clearly not the most efficient possible way to do it. How important is performance? If it's doesn't have to be amazingly fast, sure do it this way, which sounds like it's the easiest to develop.
If you want to go a step further, then the obvious point of optimization in the schematic above is to collapse the two Perl layers:
web client <-> Perl CGI script <-> C program
The question is, is it worth your time to do this? You can look at the source for the Perl wrapper and decide for yourself.
My advice would be to initially develop it the simple way and then if, for whatever reason, you decide it is insufficient, to merge the two Perl scripts into one. But for now, don't worry about it and go ahead with your idea.
So I have access to a dedicated server and want to finally create my game - it's a browser based game, fairly simple. I know PHP and MySQL fairly well and would want to integrate with them on the front end.
The question is what is a good server-side language to use either as a constant process or with cron to interface with the MySQL database to do calculations?
Ideally my requirements are:
As short a learning curve as
possible.
Easiest access to MySQL as
possible.
As hard to shoot yourself
in the foot as possible.
I'd like to avoid C/C++ if possible for the above 'shoot yourself in the foot' problems. It'd also be nice to have a secondary language to use personally so I may take it beyond this limited scope.
Thanks in advance for any insights!
You could use commandline php with cron. The great advantage of that is that you can reuse libraries that you write for your game and you already know the language. I don't think it's performance is great though.
Besides that there are a ton of languages you might choose, Python and Java are popular.
There are two good options here:
PHP
PHP is a server side language, and if you design the frontend with some robust classes, you can reuse the classes for the command-line daemon. This allows you to have a more standardized application suite, which will be easier to modify in the future. PHP can access MySQL, and since you already know it, the learning curve will be minimal.
Python
Python is an excellent server side language for an application like this. It can talk to any SQL database with a standardized instruction set, called DB API 2.0. This means taht if at any point you want to change from MySQL to PostgresSQL, you simple change:
import my_mysql_library as sql
to:
import my_postgres_library as sql
And your application won't need any other code changes. Python also contains many libraries that might come in handy, and if optimized correctly, will be faster than PHP.
Conclusion
Personally, I would use Python, for the following reasons:
Learning Experience; Programming is always about learning. At any opportunity, use a language or tool you don't already know so that you can learn it.
Language Preference; After programming in both PHP and Python, I can honestly say that there is no situation where I would prefer to use PHP over Python. Not one.
Available Libraries; Python has a very robust community, and a lot of useful libraries and packages (such as NumPy) that make things much easier for you.
With both languages you could have them run intermittently via a cron job, or you could have them run as a Daemon (which is as easy as running the script(s) while piping your output to a black hole, such as /dev/null)
Another great option for your server side scripting is perl. It has a bit of a learning curve at the start but becomes a very fast language to script in.
A great resource is http://perldoc.perl.org/
Is it possible to access & control external devices in PHP?
For example, would it be capable of changing the speed of a USB fan or change the direction of a wireless toy car.
I'm trying to go beyond web dev and I'm wondering if the programming language I use is capable of handling my ideas or should I consider changing the environment.
If these would be possible, I'd very much appreciate any pointers to reading materials or suggestions on other languages that might be more suitable.
Thanks!
On Linux it surely is possible by accessing /dev/ files. But it'll be very tedious. I'd recommend you switching to Python, Ruby, Lua or Java.
For example there are bindings for libusb for Python, Ruby, Lua and Java.
You could write an external program, then use PHP's exec (or was it system?) function to interact with the executable or script.
Seems like the most sane way to do it. Another good alternative is to build a program or script that controls an external device that can communicate with a RESTfull type API exposed via HTTP - and then use lib_curl in PHP land to talk back and forth between it. Believe me, building a basic HTTP server in C++ that can be used to be remote controlled with PHP (or JS for that matter) is very simple.
Wait
I think I read the question wrong ;)
If you want to get into really cool stuff, I say that you learn C++. C++ is a great language that not only opens a lot of doors, but also provides a good learning experience. C++ is lots and lots of fun.
In response to comment
In the case with USB its a bit different and more complicated (as USB has an established protocol and such) but serial is as easy as dumping data into a handle.
You should be able to pick up C++ to get to that point fairly soon. Either way it's a great experience.
This would be possible with a extension, but not with pure PHP code. I don't know of any extensions being able to do something like this, but I think it should be possible.
If you find a command line tool that does this, then you can control it using exec(), system(), passthru() or shell_exec() (based on what output the program gives you back)
Just be sure to escapeshellcmd() if you give access to this program from a public website.