java & php

I just did that and got, i also added the /home part in the code and it didn’t work.

[code]Array
(
[DOCUMENT_ROOT] => /home/venzo/public_html
[GATEWAY_INTERFACE] => CGI/1.1
[HTTP_ACCEPT] => text/html, application/xhtml+xml, /
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_ACCEPT_LANGUAGE] => en-US
[HTTP_CONNECTION] => Keep-Alive
[HTTP_COOKIE] =>xxxxx
[HTTP_DNT] => 1
[HTTP_HOST] => venzodigital.com
[HTTP_USER_AGENT] => Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
[PATH] => /bin:/usr/bin
[QUERY_STRING] =>
[REDIRECT_STATUS] => 200
[REMOTE_ADDR] => 108.11.168.160
[REMOTE_PORT] => 50597
[REQUEST_METHOD] => GET
[REQUEST_URI] => /cron.php
[SCRIPT_FILENAME] => /home/venzo/public_html/cron.php
[SCRIPT_NAME] => /cron.php
[SERVER_ADDR] => 50.63.148.120
[SERVER_ADMIN] => [email protected]
[SERVER_NAME] => venzodigital.com
[SERVER_PORT] => 80
[SERVER_PROTOCOL] => HTTP/1.1
[SERVER_SIGNATURE] => Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/1.0.0-fips mod_bwlimited/1.4 Server at venzodigital.com Port 80

[SERVER_SOFTWARE] => Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/1.0.0-fips mod_bwlimited/1.4
[PHP_SELF] => /cron.php
[REQUEST_TIME] => 1352266064
[argv] => Array
    (
    )

[argc] => 0

)[/code]

I’ve never messed with these kinds of scripts, so i’m not really sure what’s going on, but from what i’ve been reading, it seems to be that shell_exec is replacing the slashes with periods, but i’ve tried passthru and exec and they both do the samething, so i don’t know.

So this gives you the same error?

[php]
$res = java /home/venzo/public_html/admin/files/Autoingestion <parameters>;
echo “

” . $res . “
”;
[/php]

Also, does your java use the full absolute paths as well? Not just /public_html?

all that code did was print out what’s in $res, didn’t actually do anything. When i add -classpath after java, it gives me

Error: Could not find or load main class [email protected]

skipping the path completely.

Sorry I’m happy to troubleshoot with you but I’m mostly just guessing :slight_smile:

Any luck using escapeshellarg()? e.g.

[php]
$res = shell_exec(‘java ’ . escapeshellarg(’/home/venzo/public_html/admin/files/Autoingestion’));
echo “

” . $res . “
”;
[/php]

Also, in putty if you type ‘which java’ it should give you the full path. Try specifying the full path instead of just ‘java’ e.g. ‘/path/to/java’

typing which java didn’t do anything and that code didn’t give me any output at all. I do appreciate your help though. The only reason i’m doing it like this is because i wanted to get the path right because doing it as a regular cron job was getting me no where - course it doesn’t help that i’m 3 hours ahead of the server.

It’s been 10 years since I used Java and I never tried to use it from PHP. From the google searches I did it seems like people are only executing jar files. e.g. ‘java -jar /path/to/script.jar’

Sorry I couldn’t help

Its ok, at least you tried. I’ll do some more research on it. I guess apple is just behind on the times :slight_smile:

If you just google “execute java through php” there are quite a few threads from stackoverflow with good information. Your problem is simply a matter of trial an error - there is no specific solution. If you do figure it out, please post the solution here :slight_smile:

I got it. I saw something when i was looking at a function that got me thinking of doing it another way. This is what i came up with
[php]echo shell_exec(“cd public_html
cd admin
cd files
java Autoingestion
cd”);[/php]
I didn’t think it would work, but it did the trick.

Hmm… so likely you just needed some quotes. Do either of these work?

[php]
$res = shell_exec(“java '/home/venzo/public_html/admin/files/Autoingestion '”);
echo “

” . $res . “
”;
[/php]

[php]
$res = shell_exec("cd /home/venzo/public_html/admin/files; java Autoingestion ");
echo “

” . $res . “
”;
[/php]

Whatever the case, I’m glad you figured it out :slight_smile:

Well, now i’m having a lot of issues with part 2 of this project. Now that its downloading the files, i have to decompress the files, parse it and then import it into a table (the parsing and importing i can already do). I was reading up on how to extract it and since phar is loaded, i’m lef to learn now to how use it. This is what i have so far [php]foreach(glob(“files/.txt.gz") as $filename) {
$file = explode(’.’, basename($filename));
$nfile = $file[0].".gz";
rename($filename, ‘files/itunes/’.$nfile);
unset($filename);
}
foreach(glob("files/itunes/
.gz”) as $filename) {
// i got this from another website
try {
$phar = new PharData($filename);
$phar->extractTo(‘files/itunes/’); // extract all files
} catch (Exception $e) {
echo $e;
}
}[/php] and this is the error i’m getting

exception ‘UnexpectedValueException’ with message ‘internal corruption of phar “/home/venzo/public_html/admin/files/itunes/S_D_80045583_20121106.gz” (__HALT_COMPILER(); not found)’ in /home/venzo/public_html/admin/cron.php:17 Stack trace: #0 /home/venzo/public_html/admin/cron.php(17): PharData->_construct('files/itunes/S…’) #1 {main}

Originially i thought it was because the files download as txt.gz, so i renamed the files to just .gz, which changed the error message to what’s above. Hopefully i’m on the right track.

nevermind, i got it. I got fed up with using phar, so i went with good 'ol gunzip and shell_exec. Why change what works :slight_smile:

Well, it works as i have it if i run the script manually, but if i do it from a cron, it gives me errors on the directory changing. I’m trying the other ways that were suggested above, and method 1 doesn’t work :slight_smile:

Finally got this fixed. Ended up not needing to use a php, all i had to do was
cd /home/account/public_html/admin/files/ && java Autoingestion arguments

So if anyone is having the same issue, instead of trying to change the folder in the script, just change it in the command line, save yourself the migrane it’ll cause when all it’ll say is that it can’t find the class.

Do you know how the && differs from what I posted before?

cd /home/venzo/public_html/admin/files; java Autoingestion <parameters>

I wonder if it’s a server specific (OS) problem. What OS does your server use?

Simple Google search answered my question :slight_smile:

&& will execute only if the first command is true. So that must mean that the cd /path command failed. Did you change the path to “account” instead of “venzo”?

Just glad you got it working. There’s nothing more satisfying than solving problems yourself :smiley:

CentOS i think. What you had was for php - neither worked btw. What i just posted is what was entered in the command line to setup the cron job. Its the same concept as what we were trying to do, just not done through php.

No, account is just a generic term. I took out the real folder name for security purposes, but the number of folders is right.

Sponsor our Newsletter | Privacy Policy | Terms of Service