Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #17322 > unrolled thread

PHP Script working fine from browser but not working when executed from php

Started byandroidmaroso@gmail.com
First post2017-02-01 08:09 -0800
Last post2017-02-02 11:19 -0500
Articles 7 — 5 participants

Back to article view | Back to comp.lang.php


Contents

  PHP Script working fine from browser but not working when executed from php androidmaroso@gmail.com - 2017-02-01 08:09 -0800
    Re: PHP Script working fine from browser but not working when executed from php Jerry Stuckle <jstucklex@attglobal.net> - 2017-02-01 13:10 -0500
      Re: PHP Script working fine from browser but not working when executed from php androidmaroso@gmail.com - 2017-02-02 01:16 -0800
        Re: PHP Script working fine from browser but not working whenexecuted from php "R.Wieser" <address@not.available> - 2017-02-02 11:22 +0100
        Re: PHP Script working fine from browser but not working when executed from php Tim Streater <timstreater@greenbee.net> - 2017-02-02 13:55 +0000
        Re: PHP Script working fine from browser but not working when executed from php Ben Bacarisse <ben.usenet@bsb.me.uk> - 2017-02-02 14:11 +0000
        Re: PHP Script working fine from browser but not working when executed from php Jerry Stuckle <jstucklex@attglobal.net> - 2017-02-02 11:19 -0500

#17322 — PHP Script working fine from browser but not working when executed from php

Fromandroidmaroso@gmail.com
Date2017-02-01 08:09 -0800
SubjectPHP Script working fine from browser but not working when executed from php
Message-ID<b82c3dc5-9c07-4e8f-8e31-ae82b9960eb8@googlegroups.com>
Hi everyone, i'm trying to get a php script executed from a workflow in my crm but it does not execute .
If i test it from my browser it works fine and does what it should.
I'm not sure why this happens.
The content of the php script is the following:


<?php
$telegrambot='276929052:AAEdjgS4w3Jf8zuWl3uLhvs-mycode';
$telegramchatid=174428000;

 
function sendtelegram($msg)
{
  global $telegrambot,$telegramchatid;
  $msg= "Messaggio dal CRM.";
  $url='https://api.telegram.org/bot'.$telegrambot.'/sendMessage';$data=array('chat_id'=>$telegramchatid,'text'=>$msg);
  $options=array('http'=>array('method'=>'POST','header'=>"Content-Type:application/x-www-form-urlencoded\r\n",'content'=>http_build_query($data),),);
  $context=stream_context_create($options);
  $result=file_get_contents($url,false,$context);
  return $result;
}
//obbligatorio questo sotto per richiamare la funzione in modo tale che messaggio venga inviato
sendtelegram ("Ciao");
//Example:
//telegram('This is a test message sent to Telegram bot at'.time());
?>

Can anyone help me?
I tried it on a hosted server but also on my local installation using xampp.
The CRM i'm using is VtigerCrm

Thanks in advance.

[toc] | [next] | [standalone]


#17324

FromJerry Stuckle <jstucklex@attglobal.net>
Date2017-02-01 13:10 -0500
Message-ID<o6t87o$hr$1@jstuckle.eternal-september.org>
In reply to#17322
On 2/1/2017 11:09 AM, androidmaroso@gmail.com wrote:
> Hi everyone, i'm trying to get a php script executed from a workflow in my crm but it does not execute .
> If i test it from my browser it works fine and does what it should.
> I'm not sure why this happens.
> The content of the php script is the following:
> 
> 
> <?php
> $telegrambot='276929052:AAEdjgS4w3Jf8zuWl3uLhvs-mycode';
> $telegramchatid=174428000;
> 
>  
> function sendtelegram($msg)
> {
>   global $telegrambot,$telegramchatid;
>   $msg= "Messaggio dal CRM.";
>   $url='https://api.telegram.org/bot'.$telegrambot.'/sendMessage';$data=array('chat_id'=>$telegramchatid,'text'=>$msg);
>   $options=array('http'=>array('method'=>'POST','header'=>"Content-Type:application/x-www-form-urlencoded\r\n",'content'=>http_build_query($data),),);
>   $context=stream_context_create($options);
>   $result=file_get_contents($url,false,$context);
>   return $result;
> }
> //obbligatorio questo sotto per richiamare la funzione in modo tale che messaggio venga inviato
> sendtelegram ("Ciao");
> //Example:
> //telegram('This is a test message sent to Telegram bot at'.time());
> ?>
> 
> Can anyone help me?
> I tried it on a hosted server but also on my local installation using xampp.
> The CRM i'm using is VtigerCrm
> 
> Thanks in advance.
> 

Well, to start with, what do you mean by "not working"?  What error
messages do you get?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#17325

Fromandroidmaroso@gmail.com
Date2017-02-02 01:16 -0800
Message-ID<0bbb5cc1-bc35-4351-a8c4-b46ac7213099@googlegroups.com>
In reply to#17324
Il giorno mercoledì 1 febbraio 2017 19:10:46 UTC+1, Jerry Stuckle ha scritto:
> On 2/1/2017 11:09 AM, androidmaroso@gmail.com wrote:
> > Hi everyone, i'm trying to get a php script executed from a workflow in my crm but it does not execute .
> > If i test it from my browser it works fine and does what it should.
> > I'm not sure why this happens.
> > The content of the php script is the following:
> > 
> > 
> > <?php
> > $telegrambot='276929052:AAEdjgS4w3Jf8zuWl3uLhvs-mycode';
> > $telegramchatid=174428000;
> > 
> >  
> > function sendtelegram($msg)
> > {
> >   global $telegrambot,$telegramchatid;
> >   $msg= "Messaggio dal CRM.";
> >   $url='https://api.telegram.org/bot'.$telegrambot.'/sendMessage';$data=array('chat_id'=>$telegramchatid,'text'=>$msg);
> >   $options=array('http'=>array('method'=>'POST','header'=>"Content-Type:application/x-www-form-urlencoded\r\n",'content'=>http_build_query($data),),);
> >   $context=stream_context_create($options);
> >   $result=file_get_contents($url,false,$context);
> >   return $result;
> > }
> > //obbligatorio questo sotto per richiamare la funzione in modo tale che messaggio venga inviato
> > sendtelegram ("Ciao");
> > //Example:
> > //telegram('This is a test message sent to Telegram bot at'.time());
> > ?>
> > 
> > Can anyone help me?
> > I tried it on a hosted server but also on my local installation using xampp.
> > The CRM i'm using is VtigerCrm
> > 
> > Thanks in advance.
> > 
> 
> Well, to start with, what do you mean by "not working"?  What error
> messages do you get?
> 
> -- 
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> jstucklex@attglobal.net
> ==================

Hi, thanks for replying,

when i say it's not working i mean it doesnt send a message on telegram and no error messages are given.

If i launch the script from the browser the message gets sent on telegram, if i try to call the script from php so that it runs as if i called it manually from my browser, it won't send the telegram message and it does not disply any errors.

That's why i'm clueless!

Thanks.

[toc] | [prev] | [next] | [standalone]


#17326 — Re: PHP Script working fine from browser but not working whenexecuted from php

From"R.Wieser" <address@not.available>
Date2017-02-02 11:22 +0100
SubjectRe: PHP Script working fine from browser but not working whenexecuted from php
Message-ID<58930740$0$695$e4fe514c@news.xs4all.nl>
In reply to#17325
Maroso(?),

> ... and no error messages are given.

That may be true, but have you looked at whats returned by the
"file_get_contents" call ?    What status do you get back ?

Also,

> ... it doesnt send a message on telegram

this doesn't mean that the request isn't received.  Its possible that it is,
but is rejected.

Also, have you already tried to direct that request to a "website" you
control (maybe just a "catch-all" page running under xampp) ?   Do you see
it there ?   If not ...

In other words: try to make sure of that everything you presume happens
flawlessly actually does so.  You would not be the first guy who gets bitten
in the behind by something known to me as "Murphys Laws". :-)

Regards,
Rudy Wieser


[toc] | [prev] | [next] | [standalone]


#17327

FromTim Streater <timstreater@greenbee.net>
Date2017-02-02 13:55 +0000
Message-ID<020220171355151663%timstreater@greenbee.net>
In reply to#17325
In article <0bbb5cc1-bc35-4351-a8c4-b46ac7213099@googlegroups.com>,
<androidmaroso@gmail.com> wrote:

>Il giorno mercoledì 1 febbraio 2017 19:10:46 UTC+1, Jerry Stuckle ha scritto:

>> Well, to start with, what do you mean by "not working"?  What error
>> messages do you get?

>when i say it's not working i mean it doesnt send a message on telegram and no
>error messages are given.

You should be checking the value returned by sendtelegram instead of
just ignoring it.

-- 
"That which can be asserted without evidence, can be dismissed without 
evidence."
-- Christopher Hitchens

[toc] | [prev] | [next] | [standalone]


#17328

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2017-02-02 14:11 +0000
Message-ID<871svgn0mz.fsf@bsb.me.uk>
In reply to#17325
androidmaroso@gmail.com writes:

> Il giorno mercoledì 1 febbraio 2017 19:10:46 UTC+1, Jerry Stuckle ha scritto:
>> On 2/1/2017 11:09 AM, androidmaroso@gmail.com wrote:
<snip>
>> > The content of the php script is the following:
>> > 
>> > <?php
>> > $telegrambot='276929052:AAEdjgS4w3Jf8zuWl3uLhvs-mycode';
>> > $telegramchatid=174428000;
>> >  
>> > function sendtelegram($msg)
>> > {
>> >   global $telegrambot,$telegramchatid;
>> >   $msg= "Messaggio dal CRM.";
>> >   $url='https://api.telegram.org/bot'.$telegrambot.'/sendMessage';$data=array('chat_id'=>$telegramchatid,'text'=>$msg);
>> >   $options=array('http'=>array('method'=>'POST','header'=>"Content-Type:application/x-www-form-urlencoded\r\n",'content'=>http_build_query($data),),);
>> >   $context=stream_context_create($options);
>> >   $result=file_get_contents($url,false,$context);
>> >   return $result;
>> > }
>> > //obbligatorio questo sotto per richiamare la funzione in modo
>> > tale che messaggio venga inviato
>> > sendtelegram ("Ciao");
>> > //Example:
>> > //telegram('This is a test message sent to Telegram bot at'.time());
>> > ?>
<snip>

> If i launch the script from the browser

This phrase suggests a misunderstanding.  PHP runs on webservers, not in
browsers.  Presumably what you mean here is that you request a resource
(the browser doing it's usual thing) and the server executes the script
to generate the document the browser receives.  Again, that the usual
process -- PHP code runs on the server in response to client request for
those resources that need PHP processing.

If this is not what you mean by "i launch the script from the browser"
I, for one, need to know more.  One way is to describe exactly the
actions you take, step by step.

> the message gets sent on
> telegram, if i try to call the script from php so that it runs as if i
> called it manually from my browser, it won't send the telegram message
> and it does not disply any errors.

Similarly, I not sure what calling he script from PHP means.  Can you
say exactly what you do, step by step?

<snip>
-- 
Ben.

[toc] | [prev] | [next] | [standalone]


#17329

FromJerry Stuckle <jstucklex@attglobal.net>
Date2017-02-02 11:19 -0500
Message-ID<o6vm2v$5qj$1@jstuckle.eternal-september.org>
In reply to#17325
On 2/2/2017 4:16 AM, androidmaroso@gmail.com wrote:
> Il giorno mercoledì 1 febbraio 2017 19:10:46 UTC+1, Jerry Stuckle ha scritto:
>> On 2/1/2017 11:09 AM, androidmaroso@gmail.com wrote:
>>> Hi everyone, i'm trying to get a php script executed from a workflow in my crm but it does not execute .
>>> If i test it from my browser it works fine and does what it should.
>>> I'm not sure why this happens.
>>> The content of the php script is the following:
>>>
>>>
>>> <?php
>>> $telegrambot='276929052:AAEdjgS4w3Jf8zuWl3uLhvs-mycode';
>>> $telegramchatid=174428000;
>>>
>>>  
>>> function sendtelegram($msg)
>>> {
>>>   global $telegrambot,$telegramchatid;
>>>   $msg= "Messaggio dal CRM.";
>>>   $url='https://api.telegram.org/bot'.$telegrambot.'/sendMessage';$data=array('chat_id'=>$telegramchatid,'text'=>$msg);
>>>   $options=array('http'=>array('method'=>'POST','header'=>"Content-Type:application/x-www-form-urlencoded\r\n",'content'=>http_build_query($data),),);
>>>   $context=stream_context_create($options);
>>>   $result=file_get_contents($url,false,$context);
>>>   return $result;
>>> }
>>> //obbligatorio questo sotto per richiamare la funzione in modo tale che messaggio venga inviato
>>> sendtelegram ("Ciao");
>>> //Example:
>>> //telegram('This is a test message sent to Telegram bot at'.time());
>>> ?>
>>>
>>> Can anyone help me?
>>> I tried it on a hosted server but also on my local installation using xampp.
>>> The CRM i'm using is VtigerCrm
>>>
>>> Thanks in advance.
>>>
>>
>> Well, to start with, what do you mean by "not working"?  What error
>> messages do you get?
>>
> 
> Hi, thanks for replying,
> 
> when i say it's not working i mean it doesnt send a message on telegram and no error messages are given.
> 
> If i launch the script from the browser the message gets sent on telegram, if i try to call the script from php so that it runs as if i called it manually from my browser, it won't send the telegram message and it does not disply any errors.
> 
> That's why i'm clueless!
> 
> Thanks.
> 

OK, well, to start, on your development machine your php.ini file should
have:

error_reporting = E_ALL |
display_errors = on

Ensure you are updating the correct php.ini file - the browser and cli
may use different ones.  Executing a file with just the line

<?php phpinfo(); ?>

will show you which you are currently using.  Execute it from the CLI.
And while you're at it, check the other options it shows and compare to
the options in your web server.

Also, what version of PHP are you using - both on your web server and in
your cli?

BTW - I prefer to use cURL for operations like this.  It's much more
flexible.  But your way should work.

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex@attglobal.net
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web