How can a PHP invoke another PHP?

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
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

How can a PHP invoke another PHP?

Post by myleow »

Hi All,

I am generating WML content with a PHP file, but i need to re-invoke the same PHP file to generate the WML content again after 10 seconds. It is kinda pushing pages to the user.

I have tried the following..

push.wml

Code: Select all

<? php

  echo "<wml>";
  echo "<card blah>";
  echo "<p>";
  echo $PHP_Variable;
  echo "</p>";
  echo "</card>";
  echo "</wml>";

  if (!empty($PHP_Variable))
  {
    invoke callback.php
  }
?>
callback.php

Code: Select all

<?php
  sleep(10);
  invoke push.wml
?>
I tried using header("Location: Content"), that doesn't work because it actually sends the header to the Mobile Phone and that makes it worst because it did not activate any of the PUSH.WML content. The actual content that exist in the PUSH.WML requires at least a second for the Mobile Phone to register and activate it.

So i need a way to invoke callback.php on the server side and not sending the invokation to the Mobile Phone along with the WML content. Then the callback.php will wait 10 second on the server and then invoke PUSH.WML again.

You guys following? I don't know if i am explaining it well enough to get valid responds. Please help.

================

This is what i see from the Nokia Mobile Dev Kit's diagnos tool.

The Mobile Phone is requesting PUSH.WML then it request CALLBACK.PHP and after 10 seconds request PUSH.WML and so on so forth. So i can't use header redirection to do what i want to do.

Please help.

Thanks in advance,

Regards
Mian


feyd | last warning, use

Code: Select all

tags when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
Buddha443556
Forum Regular
Posts: 873
Joined: Fri Mar 19, 2004 1:51 pm

Post by Buddha443556 »

lostboy
Forum Contributor
Posts: 329
Joined: Mon Dec 30, 2002 8:12 pm
Location: toronto,canada

Post by lostboy »

how about using it as a function

Code: Select all

function send_wap($value)
{
  echo "<wml>"; 
  echo "<card blah>"; 
  echo "<p>"; 
  echo $value; 
  echo "</p>"; 
  echo "</card>"; 
  echo "</wml>"; 
}

while( 1=2){
  if (!empty($PHP_Variable)) 
  { 
   sleep(10); 
   send_wap($PHP_Variable); 
  } 
  [some  condition to break the loop]
}//end loop
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

That doesn't work

Post by myleow »

The above suggested solution does not solve the problem. I used ob_end_flush() and then sleep(2). What it really does is wait for the 2 seconds before flushing the WML content to the Mobile Phone.

I have attached the source code below.

Code: Select all

<?php

while($_SESSION["downloadlist"]!='')
{
    ob_start();
    include 'header.wml';
    session_start();

    echo "<wml>";
    echo "<card id="Testing PUSH"" title="Testing PUSH" newcontext="true">";
    echo "<onevent type="onenterforward">";
    echo "<go href="www.devnetwork.net"/>";
    echo "</onevent>";
    echo "<p>";
    echo "Testing PUSH";
    echo "</p>";
    echo "</card>";
    echo "</wml>";
    ob_end_flush();
    sleep(2);
  }
?>
As you can see from above, it is similar to the example you suggested. I actually tried your example but it doesn't work. So i am hoping that someone here knows how to push content out of a PHP file and then loop then content again.

I can only think of 2 ways to solve this problem.

The first would be looping back the own file. Which i could not get it to work.

Second would be invoking another file and then that file invoke this file. BUT i have no idea how to call another file. It is not using include because include just inline the code in that file to this one.

Here is the result from the suggestion given above.

Code: Select all

<?php
  function send_wap($j)
  {
    include 'header.wml';
    echo "<wml>";
    echo "<card id="testpush" title="test push">";
    echo "<p>";
    echo "Testing Push $j";
    echo "</p>";
    echo "</card>";
    echo "</wml>";
  }
  for ($i=0; $i<2; $i++)
  {
    sleep(2);
    send_wap($i);
  }
?>
Notice the for loop goes twice, this creates a 500 error on the Nokia Mobile Emulator browser.

If i changed it to 1 loop then it will wait for 2 seconds before sending the wml content. I just can't make it go on for more than 1 loop, which is very frustrating.
myleow
Forum Contributor
Posts: 194
Joined: Mon Jun 21, 2004 7:05 pm
Location: California

Post by myleow »

no one knows? =(

PHP can't call another PHP file, unlike in C++ or Java?!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

rewritting...
mox
Forum Newbie
Posts: 7
Joined: Mon Jun 14, 2004 3:17 pm

Post by mox »

What about:

eval() ?
RFairey
Forum Commoner
Posts: 52
Joined: Fri Jun 06, 2003 5:23 pm

Post by RFairey »

Are you sending headers twice in your example where you loop through it? try moving the include for header.wml outside the loop, so it is included once and not again?
Post Reply