How to call a PHP from another server using shell script? I have a PHP file and a shell script, the 2 files are stored in different server.
I have this Shell script:
#!/bin/bash
php "http://example.com/csv_import.php"
But when I run this command manually, I got an error: Could not open input
PHP:
if (($handle = fopen($directory_root."filename.csv", "r")) !== FALSE){
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){
$sql = "INSERT INTO tablename(col1,col2,col3,col4,col5)
VALUES ('".mysql_escape_string($data[0])."',
'".mysql_escape_string($data[1])."',
'".mysql_escape_string($data[2])."',
'".mysql_escape_string($data[3])."',
'".mysql_escape_string($data[4])."')";
$query = mysql_query($sql);
}
fclose($handle);
}
bashscript is broken in several ways.php"blah.php"` works for localphpfiles, not urls. you could download the php script and then run it inphplike this:curl "http://example.com/csv_import.php" | php, except that nearly any http server would not let you download the php code itself, it would execute the php on the server and then send you the result. if what you want to do is to tellexample.comto runcsv_import.php, that's possible:curl "http://example.com/csv_import.php".bashserver) to do the mysql query and save the csv, then you do need to copy the php script to that server. but maybe you want the bash server to request the csv from the http server, then the http server runs the php and creates the csv, and gives the csv to the bash server, yes? if so, usecurl "http://example.com/csv_import.php" > my.csvon the bash server, and modify the php to send back a csv, e.g., stackoverflow.com/questions/217424/…