Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed assembly code to php?

Tags:

php

assembly

I want to use assembly code to handle some critical tasks concern with performance using PHP. How can I do this? I have searched before but nothing at all.

like image 605
Jack Cood Avatar asked Oct 22 '13 08:10

Jack Cood


2 Answers

I believe you are talking about extending PHP.

You can do that by creating custom extensions in c language. A simple tutorial on how to do that you find here

like image 162
Udan Avatar answered Oct 14 '22 04:10

Udan


Using assembly for your performance problems, is like using a sledgehammer to open a dam, while there is probably a lever somewhere, that opens the dam. Better look at your structure first and see why those critical tasks have performance issues and see if you can alter the strucure.

Besides that, as php is a scripting language that is interpreted on run-time, rewriting the code to C, like in the example from Udan gives 90% of the performance boost, rewriting the C code to assembly might add some extra 10%, but will take 90% of the time.

On the other hand, the argument you are using assembly in your code gives you some brag-rights, just up until the moment another programmer looks at your code, restructures it giving a 50% performance boost and completely bypasses your assembly.

like image 35
Alfons Avatar answered Oct 14 '22 04:10

Alfons