php-general Digest 2 Oct 2013 13:52:00 -0000 Issue 8385

Topics (messages 322228 through 322234):

Re: delete S3 bucket with AWS PHP SDK
        322228 by: Aziz Saleh

Re: Algorithm Help
        322229 by: John Meyer
        322230 by: Aziz Saleh
        322231 by: Ashley Sheridan
        322232 by: Floyd Resler
        322233 by: Serge Fonville
        322234 by: Tamara Temple

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
Hey Tim,

It seems that deleteObject takes in 2 params, and you are sending it 1
param. I would recommend you look at the documentation and make sure you
are sending the right params.

Aziz


On Sun, Sep 29, 2013 at 10:29 PM, Tim Dunphy <bluethu...@gmail.com> wrote:

> Hi Aziz,
>
>  Thank you for getting back to me!
>
>  I appreciate you spotting that error.
>
> So I corrected that
>
> <?php
>   require_once 'sdk.class.php';
> if (isset($_POST['submit'])) {
>
> *  $bucket_name = $_POST['bucket_name'];*
>
>  // Create the S3 Object from the SDK
>   $s3 = new AmazonS3();
> *
>   $result = $s3->deleteObject(array(
>     'Bucket' => $bucket_name ));*
>
>
>  // The response comes back as a Simple XML Object
> // In this case we just want to know if everything was okay.
> // If not, report the message from the XML response.
>  if ((int) $response->isOK()) {
>     echo '<center>Deleted Bucket';
>     echo '<br /><br />';
>     echo '<a href=listbuckets.php>List Buckets</a></center>';
>   } else {
>     echo (string) $response->body->Message;
>   }
>  //echo '<br /><br />';
> }
> ?>
> <body>
>   <center><h3>Delete S3 Bucket</h3>
>    <form name="delete_bucket" method="post" action="delete_bucket.php">
>     <label for="bucket_name">Bucket Name:</label><br />
>    * <input type="text" id="bucket_name" name="bucket_name" /><br /><br />
> *
>     <input type="submit" name="submit" value="Delete Bucket" />
>   </form></center>
> <script>
> </body>
> </html>
>
>
> And this is the error I am currently getting:
>
>
> Warning: Missing argument 2 for AmazonS3::delete_object() in
> /var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
> variable: filename in /var/www/awssdk/services/s3.class.php on line 1581
> Warning: preg_match() expects parameter 2 to be string, array given in
> /var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
> expects parameter 2 to be string, array given in
> /var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
> exception 'S3_Exception' with message 'S3 does not support "Array" as a
> valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
> Developer Guide for more information.' in
> /var/www/awssdk/services/s3.class.php:548 Stack trace: #0
> /var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
> Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
> /var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
> /var/www/awssdk/delete_bucket.php(72): CFRuntime->__call('deleteObject',
> Array) #4 /var/www/awssdk/delete_bucket.php(72):
> AmazonS3->deleteObject(Array) #5 {main} thrown in
> /var/www/awssdk/services/s3.class.php on line 548
>
> Not sure if I'm getting closer here... but definitely appreciate any
> advice anyone may have.
>
> Thanks!
> Tim
>
>
> On Sun, Sep 29, 2013 at 5:04 PM, Aziz Saleh <azizsa...@gmail.com> wrote:
>
>> No Problem, the issue is that you referring to the invalid post element
>> $bucket_name as opposed to the correct on bucket_name.
>>
>> *$bucket_name = $_POST['$bucket_name'];*
>>
>> Should be
>>
>> *$bucket_name = $_POST['bucket_name'];*
>>
>> Aziz
>>
>>
>> On Sun, Sep 29, 2013 at 3:28 PM, Tim Dunphy <bluethu...@gmail.com> wrote:
>>
>>> Hey guys,
>>>
>>>  Sorry about that i should have posted the full code to give you some
>>> idea of context. Anyway, here it is:
>>>
>>> <?php
>>>   require_once 'sdk.class.php';
>>> if (isset($_POST['submit'])) {
>>>
>>> *  $bucket_name = $_POST['$bucket_name'];*
>>>  // Create the S3 Object from the SDK
>>>   *$s3 = new AmazonS3();*
>>>
>>> *  $result = $s3->deleteObject(array(*
>>> *    'Bucket' => $bucket_name ));*
>>>
>>>
>>>  // The response comes back as a Simple XML Object
>>>  // In this case we just want to know if everything was okay.
>>> // If not, report the message from the XML response.
>>>  if ((int) $response->isOK()) {
>>>     echo '<center>Deleted Bucket';
>>>     echo '<br /><br />';
>>>     echo '<a href=listbuckets.php>List Buckets</a></center>';
>>>   } else {
>>>     echo (string) $response->body->Message;
>>>   }
>>>  //echo '<br /><br />';
>>> }
>>> ?>
>>> <body>
>>>   <center><h3>Delete S3 Bucket</h3>
>>>    <form name="delete_bucket" method="post" action="delete_bucket.php">
>>>     <label for="bucket_name">Bucket Name:</label><br />
>>>   *  <input type="text" id="bucket_name" name="bucket_name" /><br /><br
>>> />*
>>>     <input type="submit" name="submit" value="Delete Bucket" />
>>>   </form></center>
>>>
>>> So, as you can see I am taking the 'bucket_value' from $_POST and
>>> passing it into the call to S3.
>>>
>>> When the form comes up on the web I give it the name of one of my S3
>>> buckets. The result is the following error:
>>>
>>> Notice: Undefined index: $bucket_name in
>>> /var/www/awssdk/delete_bucket.php on line 67 Warning: Missing argument 2
>>> for AmazonS3::delete_object() in /var/www/awssdk/services/s3.class.php on
>>> line 1576 Notice: Undefined variable: filename in
>>> /var/www/awssdk/services/s3.class.php on line 1581 Warning: preg_match()
>>> expects parameter 2 to be string, array given in
>>> /var/www/awssdk/services/s3.class.php on line 1042 Warning: preg_match()
>>> expects parameter 2 to be string, array given in
>>> /var/www/awssdk/services/s3.class.php on line 1043 Fatal error: Uncaught
>>> exception 'S3_Exception' with message 'S3 does not support "Array" as a
>>> valid bucket name. Review "Bucket Restrictions and Limitations" in the S3
>>> Developer Guide for more information.' in
>>> /var/www/awssdk/services/s3.class.php:548 Stack trace: #0
>>> /var/www/awssdk/services/s3.class.php(1594): AmazonS3->authenticate(Array,
>>> Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
>>> /var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array) #3
>>> /var/www/awssdk/delete_bucket.php(72): CFRuntime->__call('deleteObject',
>>> Array) #4 /var/www/awssdk/delete_bucket.php(72):
>>> AmazonS3->deleteObject(Array) #5 {main} thrown in
>>> /var/www/awssdk/services/s3.class.php on line 548
>>>
>>>
>>>
>>> I hope that clarifies my situation a bit. Sorry for not providing that
>>> sooner!
>>>
>>> Thanks
>>> Tim
>>>
>>>
>>> On Sun, Sep 29, 2013 at 1:09 PM, Aziz Saleh <azizsa...@gmail.com> wrote:
>>>
>>>> Hi Tim,
>>>>
>>>> Is the call working? Does it actually get deleted?
>>>>
>>>> This could just be an issue (which I see alot) where developers do not
>>>> check for variables or preset them before usage, causing those notices to
>>>> come up (pretty harmless most of the times).
>>>>
>>>> Aziz
>>>>
>>>>
>>>> On Sun, Sep 29, 2013 at 12:30 PM, Tim Dunphy <bluethu...@gmail.com>wrote:
>>>>
>>>>> Hi All,
>>>>>
>>>>>  I am attempting to delete an empty S3 bucket using the AWS PHP SDK.
>>>>>
>>>>>  Here's how they describe the process in the docs:
>>>>>
>>>>> $result = $client->deleteBucket(array(
>>>>>     // Bucket is required
>>>>>     'Bucket' => 'string',
>>>>> ));
>>>>>
>>>>>  You can find the full entry here:
>>>>>
>>>>> AWS PHP SDK Delete Bucket
>>>>> Docs<
>>>>> http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.S3.S3Client.html#_deleteBucket
>>>>> >
>>>>>
>>>>>
>>>>> Here's how I approached it in my code:
>>>>>
>>>>>  $s3 = new AmazonS3();
>>>>>
>>>>>   $result = $s3->deleteObject(array(
>>>>>     'Bucket' => $bucket_name ));
>>>>>
>>>>> But when I run it, this is the error I get:
>>>>>
>>>>> 'Notice: Undefined index: $bucket_name in
>>>>> /var/www/awssdk/delete_bucket.php
>>>>> on line 5 Warning: Missing argument 2 for AmazonS3::delete_object() in
>>>>> /var/www/awssdk/services/s3.class.php on line 1576 Notice: Undefined
>>>>> variable: filename in /var/www/awssdk/services/s3.class.php on line
>>>>> 1581
>>>>> Warning: preg_match() expects parameter 2 to be string, array given in
>>>>> /var/www/awssdk/services/s3.class.php on line 1042 Warning:
>>>>> preg_match()
>>>>> expects parameter 2 to be string, array given in
>>>>> /var/www/awssdk/services/s3.class.php on line 1043 Fatal error:
>>>>> Uncaught
>>>>> exception 'S3_Exception' with message 'S3 does not support "Array" as a
>>>>> valid bucket name. Review "Bucket Restrictions and Limitations" in the
>>>>> S3
>>>>> Developer Guide for more information.' in
>>>>> /var/www/awssdk/services/s3.class.php:548 Stack trace: #0
>>>>> /var/www/awssdk/services/s3.class.php(1594):
>>>>> AmazonS3->authenticate(Array,
>>>>> Array) #1 [internal function]: AmazonS3->delete_object(Array) #2
>>>>> /var/www/awssdk/sdk.class.php(436): call_user_func_array(Array, Array)
>>>>> #3
>>>>> /var/www/awssdk/delete_bucket.php(10):
>>>>> CFRuntime->__call('deleteObject',
>>>>> Array) #4 /var/www/awssdk/delete_bucket.php(10):
>>>>> AmazonS3->deleteObject(Array) #5 {main} thrown in
>>>>> /var/www/awssdk/services/s3.class.php on line 548'
>>>>>
>>>>>
>>>>> This is line 548 in the above referenced file:
>>>>>
>>>>> // Validate the S3 bucket name
>>>>>                 if (!$this->validate_bucketname_support($bucket))
>>>>>                 {
>>>>>                         // @codeCoverageIgnoreStart
>>>>>                         throw new S3_Exception('S3 does not support "'
>>>>> .
>>>>> $bucket . '" as a valid bucket name. Review "Bucket Restrictions and
>>>>> Limitations" in the S3 Developer Guide for more information.');
>>>>>                         // @codeCoverageIgnoreEnd
>>>>>                 }
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Has anyone played around enough with the AWS SDK to know what I'm doing
>>>>> wrong here? Would anyone else be able to hazard a guess?
>>>>>
>>>>> Thanks
>>>>> Tim
>>>>> --
>>>>> GPG me!!
>>>>>
>>>>> gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
>>>>>
>>>>
>>>>
>>>
>>>
>>> --
>>> GPG me!!
>>>
>>> gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
>>>
>>>
>>
>
>
> --
> GPG me!!
>
> gpg --keyserver pool.sks-keyservers.net --recv-keys F186197B
>
>

--- End Message ---
--- Begin Message ---
On 10/1/2013 12:51 PM, Floyd Resler wrote:
Here's my task: A group of kids is going to be staying with different host 
families throughout the next 8 months.  The number of kids staying with a host 
family can range from 2 to 10.  When deciding which kids should stay together 
at a host family, the idea is for the system to put together kids who have 
stayed with each other the least on past weekends.  So, if a host family can 
keep 5 kids, then the group of 5 kids who have stayed together the least will 
be chosen.

I can't think of an easy, quick way to accomplish this.  I've tried various 
approaches that have resulted in a lot of coding and being very slow.  My idea 
was to give each group of kids a score and the lowest score is the group that 
is selected.  However, this approach wound of iterating through several arrays 
several times which was really slow.  Does anyone have any ideas on this puzzle?

Thanks!
Floyd


Whatever solution you're going with will probably involve a relational database of some sort.
--- End Message ---
--- Begin Message ---
DB or flatfile?

I would create a matrix of all kids crossed with every kid. Everytime a kid
is put in a home with another kid, ++ that index. When dispatching kids,
sort by index ASC.

Aziz


On Tue, Oct 1, 2013 at 3:01 PM, John Meyer <johnme...@pueblocomputing.com>wrote:

> On 10/1/2013 12:51 PM, Floyd Resler wrote:
>
>> Here's my task: A group of kids is going to be staying with different
>> host families throughout the next 8 months.  The number of kids staying
>> with a host family can range from 2 to 10.  When deciding which kids should
>> stay together at a host family, the idea is for the system to put together
>> kids who have stayed with each other the least on past weekends.  So, if a
>> host family can keep 5 kids, then the group of 5 kids who have stayed
>> together the least will be chosen.
>>
>> I can't think of an easy, quick way to accomplish this.  I've tried
>> various approaches that have resulted in a lot of coding and being very
>> slow.  My idea was to give each group of kids a score and the lowest score
>> is the group that is selected.  However, this approach wound of iterating
>> through several arrays several times which was really slow.  Does anyone
>> have any ideas on this puzzle?
>>
>> Thanks!
>> Floyd
>>
>>
>>  Whatever solution you're going with will probably involve a relational
> database of some sort.
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Tue, 2013-10-01 at 15:09 -0400, Aziz Saleh wrote:

> DB or flatfile?
> 
> I would create a matrix of all kids crossed with every kid. Everytime a kid
> is put in a home with another kid, ++ that index. When dispatching kids,
> sort by index ASC.
> 
> Aziz
> 
> 
> On Tue, Oct 1, 2013 at 3:01 PM, John Meyer 
> <johnme...@pueblocomputing.com>wrote:
> 
> > On 10/1/2013 12:51 PM, Floyd Resler wrote:
> >
> >> Here's my task: A group of kids is going to be staying with different
> >> host families throughout the next 8 months.  The number of kids staying
> >> with a host family can range from 2 to 10.  When deciding which kids should
> >> stay together at a host family, the idea is for the system to put together
> >> kids who have stayed with each other the least on past weekends.  So, if a
> >> host family can keep 5 kids, then the group of 5 kids who have stayed
> >> together the least will be chosen.
> >>
> >> I can't think of an easy, quick way to accomplish this.  I've tried
> >> various approaches that have resulted in a lot of coding and being very
> >> slow.  My idea was to give each group of kids a score and the lowest score
> >> is the group that is selected.  However, this approach wound of iterating
> >> through several arrays several times which was really slow.  Does anyone
> >> have any ideas on this puzzle?
> >>
> >> Thanks!
> >> Floyd
> >>
> >>
> >>  Whatever solution you're going with will probably involve a relational
> > database of some sort.
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >


This sounds remarkably like homework, which we can't help you with
unless you've got a specific problem that you're stuck with.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
m

1375 GLENDALE MILFORD RD., CINCINNATI, OH 45215

On Oct 1, 2013, at 3:14 PM, Ashley Sheridan <a...@ashleysheridan.co.uk> wrote:

> On Tue, 2013-10-01 at 15:09 -0400, Aziz Saleh wrote:
> 
>> DB or flatfile?
>> 
>> I would create a matrix of all kids crossed with every kid. Everytime a kid
>> is put in a home with another kid, ++ that index. When dispatching kids,
>> sort by index ASC.
>> 
>> Aziz
>> 
>> 
>> On Tue, Oct 1, 2013 at 3:01 PM, John Meyer 
>> <johnme...@pueblocomputing.com>wrote:
>> 
>>> On 10/1/2013 12:51 PM, Floyd Resler wrote:
>>> 
>>>> Here's my task: A group of kids is going to be staying with different
>>>> host families throughout the next 8 months.  The number of kids staying
>>>> with a host family can range from 2 to 10.  When deciding which kids should
>>>> stay together at a host family, the idea is for the system to put together
>>>> kids who have stayed with each other the least on past weekends.  So, if a
>>>> host family can keep 5 kids, then the group of 5 kids who have stayed
>>>> together the least will be chosen.
>>>> 
>>>> I can't think of an easy, quick way to accomplish this.  I've tried
>>>> various approaches that have resulted in a lot of coding and being very
>>>> slow.  My idea was to give each group of kids a score and the lowest score
>>>> is the group that is selected.  However, this approach wound of iterating
>>>> through several arrays several times which was really slow.  Does anyone
>>>> have any ideas on this puzzle?
>>>> 
>>>> Thanks!
>>>> Floyd
>>>> 
>>>> 
>>>> Whatever solution you're going with will probably involve a relational
>>> database of some sort.
>>> 
>>> 
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>> 
>>> 
> 
> 
> This sounds remarkably like homework, which we can't help you with
> unless you've got a specific problem that you're stuck with.
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 

Oh, no, this is definitely not homework! :)  Although it certainly seems like a 
homework question.  This is a real world problem.  I'm keeping track of which 
kids stay with which host families in the database.  My initial approach was to 
start with kid 1 and see how many times the other kids have stayed with kid 1.  
The move on to kid 2, and so it.  This gives me a score for pairs of kids.  
However, if say three kids are staying at a host family, what is the best way 
to determine which set of three kids have stayed together the least?

Thanks!
Floyd


--- End Message ---
--- Begin Message ---
Assuming you don't have to be exact, somthing similar to this might work.

Assign each kid to a host family randomly
for each kid, check how frequently it has been combined with the kids in
its assigned family.
if it is too close, swap with a different family
when all kids in that family are processed, move on to the next family and
repeat, excluding the first family for swapping. do the same for all
families excluding the previous families. when you have completed all
families, do another iteration or two of the whole process.

Kind regards/met vriendelijke groet,

Serge Fonville

http://www.sergefonville.nl


2013/10/1 Floyd Resler <fres...@adex-intl.com>

> m
>
> 1375 GLENDALE MILFORD RD., CINCINNATI, OH 45215
>
> On Oct 1, 2013, at 3:14 PM, Ashley Sheridan <a...@ashleysheridan.co.uk>
> wrote:
>
> > On Tue, 2013-10-01 at 15:09 -0400, Aziz Saleh wrote:
> >
> >> DB or flatfile?
> >>
> >> I would create a matrix of all kids crossed with every kid. Everytime a
> kid
> >> is put in a home with another kid, ++ that index. When dispatching kids,
> >> sort by index ASC.
> >>
> >> Aziz
> >>
> >>
> >> On Tue, Oct 1, 2013 at 3:01 PM, John Meyer <
> johnme...@pueblocomputing.com>wrote:
> >>
> >>> On 10/1/2013 12:51 PM, Floyd Resler wrote:
> >>>
> >>>> Here's my task: A group of kids is going to be staying with different
> >>>> host families throughout the next 8 months.  The number of kids
> staying
> >>>> with a host family can range from 2 to 10.  When deciding which kids
> should
> >>>> stay together at a host family, the idea is for the system to put
> together
> >>>> kids who have stayed with each other the least on past weekends.  So,
> if a
> >>>> host family can keep 5 kids, then the group of 5 kids who have stayed
> >>>> together the least will be chosen.
> >>>>
> >>>> I can't think of an easy, quick way to accomplish this.  I've tried
> >>>> various approaches that have resulted in a lot of coding and being
> very
> >>>> slow.  My idea was to give each group of kids a score and the lowest
> score
> >>>> is the group that is selected.  However, this approach wound of
> iterating
> >>>> through several arrays several times which was really slow.  Does
> anyone
> >>>> have any ideas on this puzzle?
> >>>>
> >>>> Thanks!
> >>>> Floyd
> >>>>
> >>>>
> >>>> Whatever solution you're going with will probably involve a relational
> >>> database of some sort.
> >>>
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>>
> >
> >
> > This sounds remarkably like homework, which we can't help you with
> > unless you've got a specific problem that you're stuck with.
> >
> > Thanks,
> > Ash
> > http://www.ashleysheridan.co.uk
> >
> >
>
> Oh, no, this is definitely not homework! :)  Although it certainly seems
> like a homework question.  This is a real world problem.  I'm keeping track
> of which kids stay with which host families in the database.  My initial
> approach was to start with kid 1 and see how many times the other kids have
> stayed with kid 1.  The move on to kid 2, and so it.  This gives me a score
> for pairs of kids.  However, if say three kids are staying at a host
> family, what is the best way to determine which set of three kids have
> stayed together the least?
>
> Thanks!
> Floyd
>
>

--- End Message ---
--- Begin Message ---
On Oct 1, 2013, at 1:51 PM, Floyd Resler <fres...@adex-intl.com> wrote:

> Here's my task: A group of kids is going to be staying with different host 
> families throughout the next 8 months.  The number of kids staying with a 
> host family can range from 2 to 10.  When deciding which kids should stay 
> together at a host family, the idea is for the system to put together kids 
> who have stayed with each other the least on past weekends.  So, if a host 
> family can keep 5 kids, then the group of 5 kids who have stayed together the 
> least will be chosen.
> 
> I can't think of an easy, quick way to accomplish this.  I've tried various 
> approaches that have resulted in a lot of coding and being very slow.  My 
> idea was to give each group of kids a score and the lowest score is the group 
> that is selected.  However, this approach wound of iterating through several 
> arrays several times which was really slow.  Does anyone have any ideas on 
> this puzzle?
> 
> Thanks!
> Floyd
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

While definitely a tempting coding exercise, I just want to say that if this is 
urgent in any way, shuffling cards with the kids' names on them by hand might 
just be faster and less frustrating :)

OTOH, if this is something you're going to have to figure out week after week, 
then a software solution might be handy.

This is also not an *easy* problem to solve; there isn't a simple approach to 
optimizing this sort of thing because you're building a net between all the 
various kids based on past stays, in addition to the constraints of host family 
 capacity. Thus your previous code attempts might in fact be the end result.

Obviously, structuring the data is the key here.

I'm thinking of 3 primary models: Kids, Hosts, and Stays.

Kids and Hosts seem pretty obvious. Stays is the interesing model, and needs to 
have joining tables with Kids and Hosts.

A Stay will have one Host, and have many Kids and a date.

The algorithm then needs to make the graph where it can pull out the number of 
times any particular kid has stayed with another, looking something like this:

Amy:
   Ben: 10
   Jill: 3
   Carlos: 7
   Chen: 2
Ben:
   Amy: 10
   Jill: 5
   Carlos: 8
   Chen: 3
Jill:
   … and so on

Then you be able to pull through that graph and find the smallest number of 
stays for each kid.

Not simple, but I hope this helps.



--- End Message ---

Reply via email to