Running Curl from PHP CLI

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
chopper_pc
Forum Newbie
Posts: 15
Joined: Fri May 30, 2008 10:55 pm

Running Curl from PHP CLI

Post by chopper_pc »

Hi,
WIN32 IIS (2003 Server)
I have a basic PHP script that runs fine on IIS to pull an array from an MSSQL DB and use Curl to post to an external server that uses the information from my DB.
I now need to run the script from the CLI to run via the task manager.

Code: Select all

 
while($row = mssql_fetch_array($result))
{
  echo "<li>" . $row["CreatedDate"] . $row["PartNumber"] . $row["Quantity"] . $row["Manufacturer"] . $row["Condition"] . $row["Description"] . $row["Hot"] ."</li>";
 
  require_once('CurlClass.php');
  $cc = new cURL();
  $cc->post('http://www.blabla.com',part_number=$row["PartNumber"]&quantity=$row["Quantity"]&manufacturer=$row["Manufacturer"]&condition=$row["Condition"]&description=$row["Description"]&hot=$row["Hot"]');
 
Worked fine when done on the web. Using the same code calling from a batch script using C:\path\to\PHP\php.exe C:\path\to\script\foo.php returns good results when it echoes to the sreen but my Curl output on the external server is looses the variable values. It posts literally :

[part_number] => $row[\"PartNumber\"] ....................


Any ideas on what I'm doing wrong here, I have found nothing searching the net.

Thanks...
gigabit
Forum Newbie
Posts: 4
Joined: Tue Sep 15, 2009 1:48 pm

Re: Running Curl from PHP CLI

Post by gigabit »

Does the CURL class use the built in PHP curl functions?
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Running Curl from PHP CLI

Post by Mirge »

Code: Select all

 
$cc->post('http://www.blabla.com',part_number=$row["PartNumber"]&quantity=$row["Quantity"]&manufacturer=$row["Manufacturer"]&condition=$row["Condition"]&description=$row["Description"]&hot=$row["Hot"]');
 
The above is your code... and it SHOULD be throwing a parse error.

After the first argument (URL: http://www.blabla.com), your 2nd argument is NOT enclosed within quotes... sort of. It has an ending single quote, but not a starting quote. In addition, variables within single quotes do not interpolate... you would need to use double quotes.

Example:

Code: Select all

 
$foo = "bar";
 
print '$foo'; // Output: $foo
print "$foo"; // Output: bar
print $foo; // Output: bar
 
Post Reply