LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-02-2012, 08:27 AM   #1
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Is there any way to interface PHP and asm?


I'm trying to add Searching to my website, and I'm really ITCHING to write the searching stuff in asm. Is there any way to interface between PHP and asm, short of just making an EXE and redirecting between them using > and < .

To add to the problem, my hosts have 64 bit servers and I don't know 64-bit asm! (( (but that's another topic).

I think I don't really know what I'm asking, but if YOU have experience, maybe you'll get it. Just my pore confused brain at work!
 
Old 01-02-2012, 03:37 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
When you write stuff in asm it compiles to a OS specific binary (elf,pe.. etc), you don't interface directly with "asm" as such. A PHP file is a script which is compiled at runtime by the php interpreter, you may want to read up on the difference between compiled and interpreted languages. There's a good asm intro here which should help but you'll need to download the videos.
 
Old 01-03-2012, 12:40 AM   #3
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
I have been programming since '87 kbp, I know what you said. To make it clearer, what I was looking for is a way to do "inline asm", like you can do in C. Is that at all possible?
 
Old 01-03-2012, 04:59 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 244Reputation: 244Reputation: 244
All is possible, you could compile asm on the fly by executing shell commands to compile asm code in the php page (assuming building tools are available in the server), but what would be the point

I would rather compile asm code once and use it as CGI program, but frankly for a search engine I don't know if there is any advantage to use asm
 
Old 01-03-2012, 10:07 AM   #5
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
Quote:
Originally Posted by Cedrik View Post
All is possible, you could compile asm on the fly by executing shell commands to compile asm code in the php page (assuming building tools are available in the server), but what would be the point

I would rather compile asm code once and use it as CGI program, but frankly for a search engine I don't know if there is any advantage to use asm
What kind of shell commands? Could you be a bit clearer?
 
Old 01-03-2012, 11:15 AM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by resetreset View Post
... I'm really ITCHING to write the searching stuff in asm. ...
Why ? That is, can you prove that whatever string matching library you use is slow because it is written in "C" and not in assembly ?

Or maybe you are using an algorithmically inefficient library ?
 
Old 01-03-2012, 03:41 PM   #7
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
@resetrest: If you're willing to call your compiled program from a PHP script, see documentation for the following functions -
 
Old 01-04-2012, 01:10 AM   #8
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
Quote:
Originally Posted by Sergei Steshenko View Post
Why ? That is, can you prove that whatever string matching library you use is slow because it is written in "C" and not in assembly ?

Or maybe you are using an algorithmically inefficient library ?
I don't even know OF any libraries, good or bad. I'm doing it because I LIKE programming. Asm is my first love, and I haven't touched it in along time (as may be evident from the fact that I don't know 64-bit ), so - just wanted to do what my heart dictates
 
Old 01-04-2012, 03:07 AM   #9
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Quote:
Originally Posted by anomie View Post
@resetrest: If you're willing to call your compiled program from a PHP script, see documentation for the following functions -
something like this might work, or if your servers allow CGI, write the search parts as cgi scripts that provide machine parsable output and call them using curl to pass the information to them and read the output into a string, then write a snippet to parse and format the output.

as for putting the ASM code inline? php is an interpreted language and as far as i know doesn't have facilites to do such implemented.
 
Old 01-04-2012, 05:34 AM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by resetreset View Post
... just wanted to do what my heart dictates
Then read http://en.wikipedia.org/wiki/Million_Roses and look up the song on YouTube or wherever. The song is about a poor artist/painter who sold all his possessions and bought 1e6 scarlet roses to give them to the woman he loved.
 
Old 01-04-2012, 06:24 AM   #11
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,665
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
If that is what your heart dictates, then prepare to be heartbroken.

The only way to do it is to modify the PHP executable itself. Which, of course, you can do, by recompiling it. (But why?)
 
Old 01-04-2012, 08:07 AM   #12
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,783

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by sundialsvcs View Post
The only way to do it is to modify the PHP executable itself.
It seems there is a function to load a PHP extension from a shared library, you could write the shared library in assembler.
 
Old 01-04-2012, 09:39 AM   #13
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
heh sorry guys, I don't have any formal comp sci training about compiler theory or whatever, and writing a PHP *extension* would be outside my abilities. and of course, I'd have to study for a couple of years to find out all about PHP's innards. no, can't do.
just wanted to know if *someone's* done it.

ntubski, hugs and kisses for that info. haven't been to the page yet, but will
 
Old 01-05-2012, 09:29 AM   #14
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Original Poster
Rep: Reputation: 62
OK, so.... have to bend... Sergei, - could you tell me some libraries please?

Thx.
 
Old 01-05-2012, 10:39 AM   #15
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by resetreset View Post
OK, so.... have to bend... Sergei, - could you tell me some libraries please?

Thx.
Through a web search engine - enter

string matching library
.

And/or start from here:

http://en.wikipedia.org/wiki/Pattern_matching
http://en.wikipedia.org/wiki/Regular_expression
.

The first thing to try is PCRE: http://en.wikipedia.org/wiki/PCRE . And/or to "cannibalize" the library from Perl itself - it's AFAIK is faster. But both are not the fastest - I know people have written their own faster libraries in "C" - I am talking about a person who did this for work, so his library is not publicly available.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Asterisk Gateway Interface Scripting with PHP LXer Syndicated Linux News 0 01-27-2009 06:11 PM
ASM x32 vs ASM x64 Tegramon Programming 3 02-27-2008 02:26 PM
LXer: How to change Linux /UNIX system password-using a web based PHP script user interface LXer Syndicated Linux News 0 08-05-2006 08:33 PM
php admin interface for any service paul_mat Linux - Software 1 04-19-2006 01:10 PM
web interface for editing .forward file- php jspauli Programming 0 02-07-2003 10:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration