Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP - exec() - putenv() – PATH - CodeIgniter
    primarykey
    data
    text
    <p>I have downloaded a free astrology script in PHP. The script receives some data through a form (birth date and time, longitude, latitude etc) and then runs this command with its parameters passed by variables:</p> <pre><code>exec ("swetest -edir$sweph -b$utdatenow -ut$utnow -p0123456789DAttt -eswe -house$my_longitude,$my_latitude,$h_sys -flsj -g, -head", $out); </code></pre> <p>The ‘swetest’ file which is an executable for Linux is in the directory: ‘sweph’ located at the root of the site together with some other binary files with data. These binary files are the ‘Swiss Ephemeris’ which determines the position of the planets in a hor-oscope wheel. The output of this command ($out) is then stored in variables, some more calcula-tions are performed, and finally, the horoscope wheel is generated by the GD library.</p> <p>In my desktop I run windows and XAMP and my remote server is Linux. I have set the PHP version of my host to 5.3.something.</p> <p>I have uploaded the script to my host exactly as downloaded (on its own without Code Igniter) following the instructions provided and it runs perfectly without a problem. Which means my host is configured appropriately to run the exe() com-mand. </p> <p>Now I tried to adapt this script to CodeIgniter. I placed the binaries in <a href="http://example.com/codeIgniterSite/assets/sweph" rel="nofollow">http://example.com/codeIgniterSite/assets/sweph</a> . The first parameter of the “swetest” command is –edir which determines the location of the binaries and I have set it to ‘assets/sweph’ (I have set base href=’http://example.com/codeignitersite’ at the tag of the page). I have checked the values passed to the parameters ($utnow, $my_latitude, etc) and they are valid. The problem is that Code Igniter environment ignores the exec command and the $out variable is left empty. The page is then filled with errors as the calculations af-ter the exec() command are carried out without the variables being set properly.</p> <p>The first error though has to do with the command:</p> <pre><code>$swephsrc = ‘assets/sweph’; putenv("PATH=$PATH:$swephsrc") </code></pre> <p>of the script placed above the exec() and the error is: ‘Undefined variable: PATH’. </p> <p>So this must be the problem I suppose. Code Igniter must have its own system of do-ing what the putenv does. That is to add a path to the environmental path. Can someone help? I must say that when I tried to run the script locally (without CI) it produced exactly the same errors as in the remote host with CI. It did not accept the putenv. But this may be because my files are not binary locally while they are binary on the host as I uploaded them with FileZilla in binary mode according to the instructions at the site of the script author.</p> <p>I have also run the following:</p> <pre><code>echo exec ("swetest -edir$sweph -b$utdatenow -ut$utnow -p0123456789DAttt -eswe -house$my_longitude,$my_latitude,$h_sys -flsj -g, -head", $out, $error); echo $error.'&lt;br/&gt;'; echo exec('whoami', $out, $error); echo $error.'&lt;br/&gt;'; </code></pre> <p>The first $error outputs ‘127’ which means ‘file not found or something’. The second outputs my name and ‘0’ which means ‘all well’. So the Code Igniter exe-cutes the ‘whoami’ command probably because it can locate it while it has no clue where the ‘swetest’ command is. So how can I add a path to the environmental path with CI? Or is it something else?</p> <p>EDIT: I tried: $PATH = 0; before the: putenv("PATH=$PATH:$swephsrc") and it worked! The binary was executed and it filled the variables with data. Alas! My happiness did not last long... I begun receiving "Internal Server Errors" :-(. I don't know if it is a coincidence or if it has to do with my actions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload