Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a C program from php

Tags:

c

php

I have a C program I have compiled to a exe called crunch.

It takes a string and returns a hash string. It has worked for a long time but I just needed to make a small change to it. It works perfectly in terminal as such:

./crunch url-string/with-file.jpg

Spits out a nice hash string. In my php I have been executing it as such:

$crunch = '~/domains/somewhere.net/html/api/crunch';
        $code = `$crunch $code`;
        $code = mysql_real_escape_string(trim($code));

$code is initially a string which is an URL. It has been returning a hash but not any more.

I have recompiled the C a few times. Just don't get it, I have tried php exec() , passthru().

FIXED:

The issue was the difference between my Mac Unix distros and the linux server. The fix was to log into my server and compile the .c file there.

Bobs your Uncle, works again.

Thanks peeps, I did check everyones advice. Sometimes ruling out possible breaks helps focus on the issue. Virtual beers(or sparkling water) all around!

like image 909
elliotrock Avatar asked Aug 30 '26 03:08

elliotrock


2 Answers

Sigh... another non-self-helping user...

http://php.net/manual/en/function.exec.php

Take note on PERMISSIONS.

like image 183
Brian Avatar answered Aug 31 '26 17:08

Brian


A probably incomplete list would be: exec(), system(), shell_exec(), backticks, popen(), proc_open(), passthru().

EDIT:

Check this warning:

With safe mode enabled, the command string is escaped with escapeshellcmd(). Thus, echo y | echo x becomes echo y \| echo x.

From function.popen.php

like image 45
Martin L. Avatar answered Aug 31 '26 18:08

Martin L.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!